C-Structure & Union Question and Answer

C-Structure & Union Question and Answer
21. State the true statement.
  • The structure elements are always arranged in contiguous memory locations.
  • A structure can be read as a single entity
  • A structure can be a member with in it.
  • None of these
Show Answer
22. Find the output.
typedef struct bitfield
{
int a:3;
char b:7;
unsigned int c:12;
}bit;
void main ( )
{
bit b1;
printf"%d", sizeof(b1));
}

  • 22
  • 5
  • 3
  • 2
Show Answer
23. Find the output.
struct bits
{
unsigned int a:3;
};
void main ( )
{
struct bits b={8}'
printf ("5d", b.a);
}

  • 8
  • 3
  • 0
  • None of these
Show Answer
24. Find the output
struct student
{
char nm[10];
int roll;
};
void main ( )
{
struct student *s,p={raja", 5}'
s=&p;
printf("%d %s", *s.nm,*s.roll);
}

  • raja 5
  • Garbage garbage
  • Non portable pointers conversion
  • Compilation error
Show Answer
25. Structure is used for
  • Data encapsulation
  • Create memory link
  • Bit fields
  • All of the above
Show Answer
26. All structure variables are created in
  • Code area
  • Stack area
  • Data area
  • Depends on storage class
Show Answer
27. Find the output
struct st
{
char *name;
int age;
int (*p) ( );
};
void main ( )
{
struct st s={"raja", 10};
s.p=show (&s);
}
show (struct st *s)
{
printf('%s", ++s->name);
}


  • Raja
  • aja
  • Pointer to function can't be a part of structure
  • None of these
Show Answer
28. Can members of a union be same as that of structure member if union is nested withing that structure ?
  • yes
  • No
  • Can't say
  • Gives runtime error
Show Answer
29. Find the output
struct x
{
char *x;
};
void main ( )
{
struct x x={"rama"};
printf("%s", x.x);
}

  • rama
  • Compilation error
  • Runtime error
  • None of these
Show Answer
30. Find the output
struct main {
int n;
int (*p) ( );
};
void main ( )
{
struct main m;
int fun( );
m.p=fun;
* (m.p) ( );
}
fun ( )
{
printf("Hello");
}

  • Hello
  • Hello Hello
  • No output
  • Compilation error
Show Answer
Questions and Answers for Competitive Exams Various Entrance Test