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

All questions of C Structures for Class 6 Exam

What is a structure in C language.?
  • a)
    A structure is a collection of elements that can be of same data type.
  • b)
    A structure is a collection of elements that can be of different data type.
  • c)
    Elements of a structure are called members.
  • d)
    All the above
Correct answer is option 'D'. Can you explain this answer?

Structure in C language
Structure in C language is a user-defined data type that allows you to group together variables of different data types under a single name. It is a way to organize data in a meaningful way.

Elements of a structure
- A structure is a collection of elements that can be of the same data type or different data types.
- Elements of a structure are called members.

Characteristics of a structure
- A structure can contain variables, arrays, and even other structures as its members.
- You can access the members of a structure using the dot (.) operator.
- Structures are useful for representing complex data in a more organized manner.

Example:
c
struct Student {
int studentID;
char studentName[50];
float marks;
};
int main() {
struct Student s1;
s1.studentID = 101;
strcpy(s1.studentName, "John");
s1.marks = 85.5;
printf("Student ID: %d\n", s1.studentID);
printf("Student Name: %s\n", s1.studentName);
printf("Marks: %.2f\n", s1.marks);
return 0;
}
In the above example, a structure `Student` is defined with three members: `studentID`, `studentName`, and `marks`. These members are accessed using the dot operator. Structures provide a way to create complex data types in C programming.

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.

What is actually passed if you pass a structure variable to a function.?
  • a)
    Copy of structure variable
  • b)
    Reference of structure variable
  • c)
    Starting address of structure variable
  • d)
    Ending address of structure variable
Correct answer is option 'A'. Can you explain this answer?

Nilanjan Unni answered
When a structure variable is passed to a function, a copy of the structure variable is actually passed. This means that the function receives a duplicate of the original structure variable, and any modifications made to the structure within the function do not affect the original variable.

Explanation:
Here is a detailed explanation of the answer:

1. Copy of structure variable:
When a structure variable is passed to a function, a copy of the structure variable is made and passed to the function. This is done to ensure that the original structure variable remains unchanged.

2. Passing by value:
In C programming, arguments are typically passed to functions by value. This means that the value of the argument is copied and passed to the function. In the case of a structure variable, the entire structure is copied and passed to the function.

3. Modifying the copy:
Since a copy of the structure variable is passed to the function, any modifications made to the structure within the function only affect the copy and not the original variable. This is an important concept to understand when working with structures in functions.

4. Returning the modified copy:
If the function needs to modify the structure variable and return the modified value, it can do so by returning the modified copy of the structure. The original structure variable remains unchanged unless the modified copy is assigned back to it.

In conclusion, when a structure variable is passed to a function, a copy of the structure variable is actually passed. This allows the function to work with the structure without affecting the original variable. It is important to understand this concept when working with structures in functions to avoid unexpected behavior and ensure the desired results.

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?

Sarita Singh answered
Here if condition evaluates to true as a non-zero value i.e 5 is assigned to a.
So the value of a = 5 and after increment value of b = 6.
In printf statement due to pre-increment of a value of a printed will be 6 and due to post-increment of b value of b printed will be 6 and not 7.

What is the output of the following program?
#include<stdio.h>
int c[10] = {1,2,3,4,5,6,7,8,9,10};   
main()
{
   int a, b=0;
   for(a=0;a<10;++a)
      if(c[a]%2 == 1)
         b+=c[a];
   printf("%d", b);
}
  • a)
    20
  • b)
    24
  • c)
    25
  • d)
    30
Correct answer is option 'C'. Can you explain this answer?

Maitri Bajaj answered

Explanation:

Initial Array:
- The initial array c contains values from 1 to 10.

Loop:
- The for loop iterates through each element of the array c.
- It checks if the current element is odd (since it checks if c[a] % 2 == 1).
- If the element is odd, it adds the element to the variable b.

Calculations:
- In the array c, the odd numbers are 1, 3, 5, 7, 9.
- Adding these odd numbers (1 + 3 + 5 + 7 + 9) gives the result 25.

Output:
- The final result stored in variable b is 25.
- Therefore, when the program is executed, it will output 25.

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?

Sarita Singh answered
First of all for loop have no braces so for loop on have only next line in its body.
for( ; digit <= 9; )
digit++;
After completing for loop digit = 10;
next statement digit *= 2; i.e digit = digit * 2 = 20;
next statement digit--; i.e 20-- => 19
So final value of digit is 19

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 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.

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 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.

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.

Signup to see your scores go up within 7 days!

Study with 1000+ FREE Docs, Videos & Tests
10M+ students study on EduRev