C - Structure and Union Questions and Answers
The topic C – Structure and Union is frequently featured in C programming MCQ sections of campus placements and technical interviews for companies like Infosys, TCS, and Wipro. Understanding how structures and unions store data is vital for efficient memory management in C. This topic strengthens the fundamentals of data organization, helping candidates write optimized and modular code. Practicing C programming questions and answers on Structure and Union will enhance your understanding and help you tackle programming interview challenges effectively.
C - Structure and Union
Showing 10 of
51 questions
31. A bit field is
- a pointer variable in a structure.
- one bit or a set of adjacent bits within a word.
- a pointer variable in a union.
- not used in C.
33. Identify the wrong statement(s).
- Bit fields have addresses
- Bit fields can be read using scanf()
- Bit fields can be accessed using pointer
- all the above
34. Identify the correct statement (s).
- Bit fields are not arrays.
- Bit fields cannot hold the values beyond their limits.
- Bit fields may be unnamed also.
- All the above.
35. About structures which of the following is true. 1. Struture members are aligned in memory depending on their data type. 2. The size of a structure may not be equal to the sum of the sizes of its members.
- only option 1
- only option 2
- both options 1 and 2
- neither option 1 nor 2
36. struct data { int day; int month; int year; }; main ( ) { struct date *d; ... ++d->day; /*satementN*/ .... } then the statement statementN ...
- increments the pointer to point the month
- increment the value of day
- increment d by sizeof(struct date)
- none
37. struct cost_record { long cost_no; char cost_name[31]]; double current_bal; } CUST_REC; Is the sample code above a usable structure variable declaration?
- Yes. CUST_REC can be used to access its members with the "_>" operator.
- No. A typedef must be added before "struct".
- yes. CUST REC can be used to access its members with the "." operator.
- No. CUST REC must be in lowercase letters.
38. struct car { int speed; char type [10]; } vehicle; struct car *ptr; ptr = &vehicle; Referring to the sample code above, which of the following will make the speed equal to 200?
- (*ptr).speed=200;
- (*ptr)->speed = 200;
- *ptr.speed = 200;
- &ptr.speed = 200;
39. Consider the following structure. struct numname { int no; char name [25]; }; struct numname n1 [ ] = { {12, "Raja"}, {15, "selvan"}, {18, "Prema"}, {21, "Naveen"} }; The output for the following statement would be: printf ("%d, %d",n1 [ 2].no, (* (n1 + 2)). no);
- 18, ASCII value p
- 18, 18
- 18, ASCII value r
- 18, ASCII value f e
40. struct customer *ptr = malloc (sizeof (struct customer)); Given the sample allocation for the pointer "ptr" found above, which statement would be used to reallocate ptr to be an array of 10 elements?
- ptr = rea11oc ( ptr, 10 * sizeof (struct customer ));
- ptr = rea11oc (ptr, 9* sizeof (struct customer));
- rea11oc ( ptr, 9* sizeof (struct customer));
- rea11oc ( ptr, 10 * sizeof ( struct customer));