Ques 1. Assume that the size of an integer is 4 bytes and size of character is 1 byte. What will be the output of following program?
C options :
A)12
B)16
C)8
D)4
C options :
A)9 7 5 3 1
B)9 8 7 6 5 4 3 2 1
C)Infinite loop
D)9 7 5 3
C Options :
A)Geeks
B)runtime error
C)Geeksforgeeks
D)compile time error
C Options :
A)1
B)2
C)0
D)No output
C
#include <stdio.h>
union test {
int x;
char arr[8];
int y;
} u;
int main()
{
printf("%u", sizeof(u));
return 0;
}
Answer - CExplanation : In union data type, the memory required to store a union variable is the memory required for the largest element of an union. Ques 2. What will be the output of following program?
#include <stdio.h>
int main()
{
int n;
for (n = 9; n != 0; n--)
printf("%d", n--);
}
Answer - CExplanation : The loop will run infinite time because n will never be equal to 0. Ques 3. What will be the output of following program?
#include <stdio.h>
int main()
{
int x = 1;
if (x = 0)
printf("Geeks");
else
printf("Geeksforgeeks");
}
Answer - CExplanation : Here we are assigning(=) and not comparing(==) x with 0 which is not true so the else part will execute and print Geeksforgeeks. Ques 4.What will be output of following c code?
#include <stdio.h>
int main()
{
int i = 2, j = 2;
while (i + 1 ? --i : j++)
printf("%d", i);
return 0;
}
Answer : AExplanation: Consider the while loop condition:
i + 1 ? -- i : ++jIn first iteration: i + 1 = 3 (True), So ternary operator will return
-–i i.e. 1In C, 1 means true so while condition is true. Hence printf statement will print 1 In second iteration: i + 1 = 2 (True), So ternary operator will return
-–i i.e. 0In C, zero means false so while condition is false. Hence program control will come out of the while loop. Ques 5. Assume that the size of an integer is 4 bytes and size of character is 1 byte. What will be the output of following program?
#include <stdio.h>
struct test {
int x;
char arr[8];
int y;
} u;
int main()
{
printf("%u", sizeof(u));
return 0;
}
options :
A)12
B)16
C)8
D)4
Answer - BExplanation : In structure data type, The amount of memory required to store a structure variable is the sum of memory size of all members.