C - Structure and Union Questions and Answers

Practice Mode
Showing 10 of 51 questions
Q41
Which of the following will define a type NODE that is a node in a linked list.
  • A struct node{ noee *next; intx;}; typedef struct node NODE;
  • B typedef struct NODE { struct NODE *NECT; INT X; };*
  • C typedef struct node NODE; struct node { NODE *next; intx;};
  • D typedef struct { NODE *next; int x; } NODE;
Answer: Option C
Q42
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;
  • A 16 bytes
  • B 13 bytes
  • C 8 bytes
  • D 4 bytes
Answer: Option C
Q43
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 /
  • A ptr = ptr + sizeof (rainbow.a);
  • B ptr = (void*) ((union reainbow*) ptr +1);
  • C ptr = pr + sizeof (*ptr);
  • D ++ (int *) ptr;
Answer: Option B
Q44
Which is the valid declaration ?
  • A # typedef struct {int i;} in;
  • B typedef struct in {int i;};
  • C # typedef struct int {int i;};
  • D typedef struct {int i;} in;
Answer: Option D
Q45
The following statement is "The soze of a struct is always equal to the sum of the sizes of its members."
  • A valid
  • B invalid
  • C can't say
  • D insuficient information
Answer: Option C
Q46
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
  • A options (i) and (iii)
  • B option (ii) only
  • C options (ii) and (iv)
  • D option iv only
Answer: Option B
Q47
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;
  • A options 1, 2 and 4
  • B options 2 and 3
  • C options 1 and 2
  • D options 1, 3 and 4
Answer: Option A
Q48
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;
  • A 11
  • B 6
  • C 4
  • D 5
Answer: Option B
Q49
What is the output of the following code / union { int no; char ch; } u; u. ch = '2'; u.no = 0, printf ("%d", u.ch);
  • A 2
  • B 0
  • C null character
  • D none
Answer: Option B
Q50
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;
  • A all are correct
  • B options (i), (ii) and (iv)
  • C options (ii) and (iv)
  • D option (ii) only
Answer: Option C
Questions and Answers for Competitive Exams Various Entrance Test