C - Structure and Union Questions and Answers

Take Exam

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

41. Which of the following will define a type NODE that is a node in a linked list.

  • struct node{ noee *next; intx;}; typedef struct node NODE;
  • typedef struct NODE { struct NODE *NECT; INT X; };*
  • typedef struct node NODE; struct node { NODE *next; intx;};
  • typedef struct { NODE *next; int x; } NODE;
Show Answer Report

42. The size of the following union, where an int occupies 4 bytes of memory is union arc { char x; int y; char ax [8]; } ahs;

  • 16 bytes
  • 13 bytes
  • 8 bytes
  • 4 bytes
Show Answer Report

43. union rainbow { int a [ 5]; float x [5]; }; union rainbow color [20]; void *ptr = color; Which of the following is the correct way to increment the variable "ptr" to point to the next member of the array from the sample above /

  • ptr = ptr + sizeof (rainbow.a);
  • ptr = (void*) ((union reainbow*) ptr +1);
  • ptr = pr + sizeof (*ptr);
  • ++ (int *) ptr;
Show Answer Report

44. Which is the valid declaration ?

  • # typedef struct {int i;} in;
  • typedef struct in {int i;};
  • # typedef struct int {int i;};
  • typedef struct {int i;} in;
Show Answer Report

45. The following statement is "The soze of a struct is always equal to the sum of the sizes of its members."

  • valid
  • invalid
  • can't say
  • insuficient information
Show Answer Report

46. struct adr { char *name; char *city; int zip; }; struct adr *adradr; whioch are valid references? (i) adr->name (ii) adradr->name (iii) adr. zip (iv) adradr.zip

  • options (i) and (iii)
  • option (ii) only
  • options (ii) and (iv)
  • option iv only
Show Answer Report

47. struct { int x; int y; }abc; you cannot access x by the following: 1. abc->x; 2. abc[ 0 ] ->x; 3. abc.x; 4. (abc)->x;

  • options 1, 2 and 4
  • options 2 and 3
  • options 1 and 2
  • options 1, 3 and 4
Show Answer Report

48. What is the size of 'q' in the following program ? Assume int takes 4 bytes. union { int x; char y; struct { char x; char y; int xy; }p; }q;

  • 11
  • 6
  • 4
  • 5
Show Answer Report

49. What is the output of the following code / union { int no; char ch; } u; u. ch = '2'; u.no = 0, printf ("%d", u.ch);

  • 2
  • 0
  • null character
  • none
Show Answer Report

50. Which of these are valid declarations ? (i) union ( int i; int j; }; (ii) union u-tag { int i; int j; }u; (iii) union { int i; int j; FILE *k; }; (iv) union { int i; int j; } U;

  • all are correct
  • options (i), (ii) and (iv)
  • options (ii) and (iv)
  • option (ii) only
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test