C Programming Multiple choice Questions and Answers on Sizeof Keyword
https://www.computersprofessor.com/2017/09/c-programming-multiple-choice-questions.html
1. What is the sizeof(char) in a 32-bit C compiler?
a. 1 bit
b. 2 bits
c. 1 Byte
d. 2 Bytes
a. 1 bit
b. 2 bits
c. 1 Byte
d. 2 Bytes
Answer:c
2. What is the output of this C code?
#include
printf("%d", sizeof('a'));
a. 1
b. 2
c. 4
d. None of the mentioned
b. 2
c. 4
d. None of the mentioned
Answer:c
3. Size of an array can be evaluated by:
(Assuming array declaration int a[10];)
a. sizeof(a);
b. sizeof(*a);
c. sizeof(a[10]);
d. 10 * sizeof(a);
(Assuming array declaration int a[10];)
a. sizeof(a);
b. sizeof(*a);
c. sizeof(a[10]);
d. 10 * sizeof(a);
Answer:a
4. What is the output of this C code?
#include
union temp
{
char a;
char b;
int c;
}t;
int main()
{
printf("%d", sizeof(t));
return 0;
}
a. 1
b. 2
c. 4
d. 6
b. 2
c. 4
d. 6
Answer:c
5. Which of the following is not an operator in C?
a. ,
b. sizeof()
c. ~
d. None of the mentioned
a. ,
b. sizeof()
c. ~
d. None of the mentioned
Answer:d
6. Which among the following has the highest precedence?
a. &
b. <<
c. sizeof()
d. &&
a. &
b. <<
c. sizeof()
d. &&
Answer:c
7. The sizeof(void) in a 32-bit C is_____.
a. 0
b. 1
c. 2
d. 4
a. 0
b. 1
c. 2
d. 4
Answer:b
8. What type of value does sizeof return?
a. char
b. short
c. unsigned int
d. long
a. char
b. short
c. unsigned int
d. long
Answer:c
a. sizeof(P) is greater than sizeof(Q)
b. sizeof(P) is less than sizeof(Q)
c. sizeof(P) is equal to sizeof(Q)
d. None of the mentioned
a. sizeof(P) is greater than sizeof(Q)
b. sizeof(P) is equal to sizeof(Q)
c. sizeof(P) is less than to sizeof(Q)
d. None of the mentioned
a. sizeof(struct stemp*) > sizeof(union utemp*) > sizeof(char *)
b. sizeof(struct stemp*) < sizeof(union utemp*) < sizeof(char *)
c. sizeof(struct stemp*) = sizeof(union utemp*) = sizeof(char *)
d. The order Depends on the compiler
a. pointers
b. functions
c. macro definition
d. None of the mentioned
9. Which among the following is never possible in C when members are different in a structure and union?
//Let P be a structure
//Let Q be a union
//Let P be a structure
//Let Q be a union
a. sizeof(P) is greater than sizeof(Q)
b. sizeof(P) is less than sizeof(Q)
c. sizeof(P) is equal to sizeof(Q)
d. None of the mentioned
Answer:d
10. Which among the following is never possible in C when members in a structure are same as that in a union?
//Let P be a structure
//Let Q be a union
//Let P be a structure
//Let Q be a union
a. sizeof(P) is greater than sizeof(Q)
b. sizeof(P) is equal to sizeof(Q)
c. sizeof(P) is less than to sizeof(Q)
d. None of the mentioned
Answer:c
11. What will be the size of the following structure?
#include
struct temp
{
int a[10];
char p;
};
a. 5
b. 11
c. 41
d. 44
b. 11
c. 41
d. 44
Answer:d
12. Comment on the output of following C program?
#include
main()
{
int a = 1;
printf("size of a is %d, ", sizeof(++a));
printf("value of a is %d", a);
};
a. size of a is 4, value of a is 1
b. size of a is 4, value of a is 2
c. size of a is 2, value of a is 2
d. size of a is 2, value of a is 2
b. size of a is 4, value of a is 2
c. size of a is 2, value of a is 2
d. size of a is 2, value of a is 2
Answer:a
13. Which among the following is right?
a. sizeof(struct stemp*) > sizeof(union utemp*) > sizeof(char *)
b. sizeof(struct stemp*) < sizeof(union utemp*) < sizeof(char *)
c. sizeof(struct stemp*) = sizeof(union utemp*) = sizeof(char *)
d. The order Depends on the compiler
Answer:c
14. Comment on the following C code?
#include
printf("%d", sizeof(strlen("HELLOWORLD")));
a. Output, 4
b. Output, 10
c. Output, 16
d. Error, sizeof cannot evaluate size of a function.
b. Output, 10
c. Output, 16
d. Error, sizeof cannot evaluate size of a function.
Answer:a
15. Which of the following cannot be used inside sizeof?
a. pointers
b. functions
c. macro definition
d. None of the mentioned
Answer:d
16. Comment on the following C code?
#include
(sizeof double = 8, float = 4, void = 1)
#define PI 3.14
int main()
{
printf("%d", sizeof(PI));
}
a. Output is 8
b. Output is 4
c. Output is 1
d. Error, we can’t use sizeof on macro-definitions
b. Output is 4
c. Output is 1
d. Error, we can’t use sizeof on macro-definitions
Answer:a