MCQ - Structure And Union in C Programming

21. What is the output of this program?

#include <stdio.h>
struct test {
int x;
char y;
} test;
int main()
{
test.x = 10;
test.y = 'A';
printf("%d %c", test.x,test.y);
return 0;
}


A. 10 A
B. garbage value garbage value
C. Compilation Error
D. None of these

View Answer


22. What is the output of this program?

#include <stdio.h>
struct result{
char sub[20];
int marks;
};
void main()
{
struct result res[] = { {"Maths",100},
{"Science",90},
{"English",85}
};
printf("%s ", res[1].sub);
printf("%d\n", (*(res+2)).marks);
}

A. Maths 100
B. Science 85
C. Science 90
D. Science 100

View Answer


23. What will be the size of the following structure?

struct demo{
int a; char b; float c; }

A. 12
B. 8
C. 10
D. 9

View Answer


24. What is the output of this program?

#include<stdio.h>
void main()
{
struct demo{
char * a;
int n;
};
struct demo p = {"hello", 2015};
struct demo q = p;
printf("%d", printf("%s",q.a));
}

A. hello
B. 5hello
C. hello5
D. 6hello

View Answer


25. What is the output of this program?
#include<stdio.h>
int main()
{
union demo {
int x; int y;
};
union demo a = 100;
printf("%d %d",a.x,a.y);
}

A. 100 0
B. 100 100
C. 0 0
D. Compilation Error

View Answer


26. What is the output of this program?

#include<stdio.h>
int main()
{
enum days {MON=-1, TUE, WED=4, THU, FRI, SAT};
printf("%d, %d, %d, %d, %d, %d", MON, TUE, WED, THU, FRI, SAT);
return 0;
}

A. -1 0 4 5 6 7
B. -1 0 1 2 3 4
C. 0 1 2 3 4 5
D. Error

View Answer


27. What is the output of this program?

#include<stdio.h>
int main(){
struct simp
{
int i = 6;
char city[] = "chennai";
};
struct simp s1;
printf("%d",s1.city);
printf("%d", s1.i);
return 0;
}

A. chennai 6
B. Nothing will be displayed
C. Runtime Error
D. Compilation Error

View Answer


28. What is the output of this program?

#include<stdio.h>
struct
{
int i;
float ft;
}decl;
int main(){
decl.i = 4;
decl.ft = 7.96623;
printf("%d %.2f", decl.i, decl.ft);
return 0;
}

A. 4 7.97
B. 4 7.96623
C. Compilation error
D. None of the above

View Answer


29. What is the output of this program?

void main()
{
struct bitfields {
int bits_1: 2;
int bits_2: 9;
int bits_3: 6;
int bits_4: 1;
}bit;
printf("%d", sizeof(bit));
}

A. 2
B. 3
C. 4
D. 0

View Answer


30. What is the output of this program?

#include<stdio.h>
int main(){
struct leader
{
char *lead;
int born;
};
struct leader l1 = {"AbdulKalam", 1931};
struct leader l2 = l1;
printf("%s %d", l2.lead, l1.born);
}

A. Compilation error
B. Garbage value 1931
C. AbdulKalam 1931
D. None of the above

View Answer


31. What is the output of this program?
#include<stdio.h>
struct employee
{
char *empname;
int salary;
};
int main()
{
struct employee e, e1;
e.empname = "Sridhar";
e1 = e;
printf("%s %s", e.empname, e1.empname);
return 0;
}

A. Garbage value Sridhar
B. Sridhar Garbage value
C. Sridhar Sridhar
D. Compilation Error

View Answer







Also check :


Discussion


* You must be logged in to add comment.