All Exams  >   Class 6  >   C Programming for Beginners  >   All Questions

All questions of C Structures for Class 6 Exam

What will be the output of the given program?
#include<stdio.h>
void main()
{
    int a=11,b=5;
    if(a=5) b++;
    printf("%d %d", ++a, b++);
}
  • a)
    12 7
  • b)
    5 6
  • c)
    6 6
  • d)
    6 7
Correct answer is option 'C'. Can you explain this answer?

Kunal Ghosh answered
Explanation:

Initial values:
- a = 11
- b = 5

Condition in if statement:
- The condition in the if statement is (a=5).
- Here, a is assigned the value 5 (a=5) which is a non-zero value, so the condition will be true.
- As a result, the code inside the if statement will be executed.

Code inside the if statement:
- Inside the if statement, b will be incremented by 1 (b++). So, b will become 6.

Output:
- After the if statement, a will be incremented by 1 (++a). So, a will become 12.
- The value of b will be incremented by 1 as well (b++). So, b will become 7.
Therefore, the output of the program will be:

6 6

What will be the final value of the digit?
void main()
{
   int digit = 0;
   for( ; digit <= 9; )
   digit++;
   digit  *= 2;
   --digit;
}
  • a)
    -1   
  • b)
    17
  • c)
    19
  • d)
    16
Correct answer is option 'C'. Can you explain this answer?

The provided code snippet is incomplete and does not specify the condition for the for loop. Without the condition, it is not possible to determine the final value of the digit variable.

What is the output of C program with structures.?
int main()
{
    struct paint{
        int type;
        int color;
    }p1, p2;
    p1.type=1;
    p1.color=5;
    if(sizeof(p1)==sizeof(p2))
    {
        printf("SAME");
    }
    else
    {
        printf("DIFFERENT");
    }
    return 0;
}
  • a)
    SAME
  • b)
    DIFFERENT
  • c)
    Compiler error
  • d)
    None of the above
Correct answer is option 'A'. Can you explain this answer?

Sankar Saha answered
"The sizes of p1 and p2 are equal." ); } else { printf("The sizes of p1 and p2 are not equal." ); } return 0;}

The output of this program will be "The sizes of p1 and p2 are equal." This is because the sizeof operator is used to check the size of the two structures p1 and p2, which are declared to have the same type and therefore the same size. The program then outputs a message to indicate that the sizes are equal.

Choose a correct statement about C structures.
  • a)
    Structure elements can be initialized at the time of declaration.
  • b)
    Structure members can not be initialized at the time of declaration
  • c)
    Only integer members of structure can be initialized at the time of declaraion
  • d)
    None of the above
Correct answer is option 'B'. Can you explain this answer?

Maya Mehta answered
Explanation:

Structure Elements Initialization:
In C programming, a structure is a user-defined data type that allows you to combine different data types into a single entity. Each data type inside the structure is called a member.

Initializing Structure Elements:
Structure elements can be initialized at the time of declaration using the following syntax:
struct structureName variableName = {value1, value2, ..., valueN};

Example:
```c
#include

// Define a structure
struct student {
char name[50];
int age;
float marks;
};

int main() {
// Initialize structure elements
struct student s1 = {"John", 20, 85.5};
printf("Name: %s\n", s1.name);
printf("Age: %d\n", s1.age);
printf("Marks: %.2f\n", s1.marks);

return 0;
}
```

Output:
```
Name: John
Age: 20
Marks: 85.50
```

Explanation:
In the above example, a structure named "student" is defined with three members: "name" (character array), "age" (integer), and "marks" (float). The structure variable "s1" is declared and initialized with values for each member at the time of declaration itself. The initialized values are then printed using printf statements.

Correct Statement:
The correct statement about C structures is option 'B': Structure members cannot be initialized at the time of declaration.

Explanation:
In C programming, structure members cannot be directly initialized at the time of declaration. Instead, the structure variable can be initialized with values for each member.

Example:
```c
#include

// Define a structure
struct student {
char name[50];
int age;
float marks;
};

int main() {
// Initialize structure variable
struct student s1 = {"John", 20, 85.5};
printf("Name: %s\n", s1.name);
printf("Age: %d\n", s1.age);
printf("Marks: %.2f\n", s1.marks);

return 0;
}
```

Output:
```
Name: John
Age: 20
Marks: 85.50
```

Explanation:
In the above example, the structure variable "s1" is declared and initialized with values for each member using curly braces and separating the values with commas. The initialized values are then printed using printf statements.

Therefore, the correct statement is option 'B': Structure members cannot be initialized at the time of declaration.

Find the output of the following program.
#include<stdio.h>
void main()
{
   int y=10;
   if(y++>9 && y++!=10 && y++>11)
      printf("%d", y);
   else
      printf("%d", y);
}
  • a)
    11
  • b)
    12
  • c)
    13
  • d)
    14
Correct answer is option 'C'. Can you explain this answer?

Sarita Singh answered
Here if Statement is true and if statement executes left to right. Since its AND operator so all the condition should be check until it finds any false statement. Initially y = 10 In 1st condition: y++>9 which is true and y become 11 in next use. In 2nd condition: y++!=10 which is also true and y become 12 in next use In 3rd condition: y++>11 which is also true and y become 13 in next use After that printf statement will execute and print y = 13

What will be the output of the given program?
#include<stdio.h>
void main()
{
    int value1, value2=100, num=100;
    if(value1=value2%5) num=5;
    printf("%d %d %d", num, value1, value2);
}
  • a)
    100 100 100   
  • b)
    5 0 20
  • c)
    5 0 100
  • d)
    100 0 100
Correct answer is option 'D'. Can you explain this answer?

Sarita Singh answered
Expression value2%5 is equal to 0 and this value assigned to value1.
Therefore if condition reduces to if(0) so it fails.
Therefore body of if will not be executed i.e num = 5 will not be assigned.
So at printf num = 100 , value1 = 0 and value2 = 100.

What will be the output of given program?
#include<stdio.h>
void main()
{
    int a=1;
    if("%d=hello", a);
}
  • a)
    complier error
  • b)
    no error no output
  • c)
    0
  • d)
    1
Correct answer is option 'B'. Can you explain this answer?

Sarita Singh answered
the if is conditional and it checks for expression whether it is zero or non-zero so it doesn't print any data it is clear and it is clearly seen that there is not a single syntax error therefore no complier error.
After compling the program will be executed but there is not a single printf statement so it is executed but will not give any output.

What will be the output of given program?
#include<stdio.h>
void main()
{
      int i=1, j=-1;
      if((printf("%d", i)) < (printf("%d", j))) 
            printf("%d", i);
      else 
            printf("%d", j);
}
  • a)
    1 -1 1
  • b)
    1 -1 -1
  • c)
    1
  • d)
    -1
Correct answer is option 'A'. Can you explain this answer?

Sarita Singh answered
Here if statement is executed since we know that printf() function return the number of character print.
Here printf("%d", i) return 2 because it print 1 and newline i.e 2.
And, printf("%d', j) return 3 because it print -1 and newline i.e number of character is 3.
Therefore if statement look like if(2<3) yes its true.
So if statement will execute. And answer is 1 -1 1.

Chapter doubts & questions for C Structures - C Programming for Beginners 2025 is part of Class 6 exam preparation. The chapters have been prepared according to the Class 6 exam syllabus. The Chapter doubts & questions, notes, tests & MCQs are made for Class 6 2025 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests here.

Chapter doubts & questions of C Structures - C Programming for Beginners in English & Hindi are available as part of Class 6 exam. Download more important topics, notes, lectures and mock test series for Class 6 Exam by signing up for free.

Top Courses Class 6