C Practice Test on Structures and Unions

This “C Practice Test on Structures and Unions” providing set of technical and objective type questions on Structures and Unions to test your programming skills.


1. What is the Output of following Code?
#include <stdio.h>
int main()
{
struct sample
{
sample *s;
}t;
printf(“%d”,sizeof(t.s));
return 0;
}

 
 
 
 

2. A -> B is syntactically correct if?

 
 
 
 

3. What is the Output of following Code?
#include<stdio.h>
union un
{
int a, b;
};
void main()
{
union un var ;
var.a=10;
var.b=20;
printf(“a val : %d\n”, var.a);
}

 
 
 
 

4. What is the Output of following Code?
#include <stdio.h>
struct sample
{
int a;
}sample;
int main()
{
sample.a = 100;
printf(“%d”,sample.a);
return 0;
}

 
 
 
 

5. Which of the following Statement about Union is false?

 
 
 
 

6. What is the Output of following Code?
#include<stdio.h>
union un
{
short s;
char c[2];
};
void main()
{
union un var ;
var.c[0]=2;
var.c[1]=3;
printf(“s val : %d\n”, var.s);
}

 
 
 
 

7. Difference between structure, union, and enumeration?

 
 
 
 

8. What is the Output of following Code?
#include <stdio.h>
struct student
{
char *name = “Kowshik” ;
};
void main()
{
struct student m ;
printf(“%c”, m.name);
}

 
 
 
 

9. If code contains instruction “s.t.b = 10” indicates…

 
 
 
 

10. What is the Output of following Code?
#include<stdio.h>
union un
{
int a, b;
};
void main()
{
printf(“%d\n”, sizeof(union un));
}

 
 
 
 

Question 1 of 10

Share this