C Programming Questions and Answers – Sizeof Keyword – 2

«
»
This section on C interview questions and answers focuses on “Sizeof operator”. One shall practice these interview questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C Interview questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C interview questions on “Sizeof operator” along with answers, explanations and/or solutions:

1. 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
advertisement

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
View Answer

Answer: d
Explanation: None.

2. Which among the following is never possible in C when members in a structure are the same as that in a union?

   //Let P be a structure
   //Let Q be a union
advertisement
advertisement

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
View Answer

Answer: c
Explanation: None.

3. What will be the size of the following C structure?

advertisement
  1.     #include <stdio.h>
  2.     struct temp
  3.     {
  4.         int a[10];
  5.         char p;
  6.     };

a) 5
b) 11
c) 41
d) 44
View Answer

Answer: d
Explanation: None.
advertisement

4. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     main()
  3.     {
  4.         int a = 1;
  5.         printf("size of a is %d, ", sizeof(++a));
  6.         printf("value of a is %d", a);
  7.     };

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
View Answer

Answer: a
Explanation: None.
advertisement

5. Which among the following statement 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
View Answer

Answer: c
Explanation: None.

6. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     printf("%d", sizeof(strlen("HELLOWORLD")));

a) Output, 4
b) Output, 10
c) Output, 16
d) Error, sizeof cannot evaluate size of a function
View Answer

Answer: a
Explanation: None.

7. Which of the following cannot be used inside sizeof?
a) pointers
b) functions
c) macro definition
d) none of the mentioned
View Answer

Answer: d
Explanation: None.

8. What will be the output of the following C code?

  1.     #include <stdio.h>
  2.     (sizeof double = 8, float = 4, void = 1)
  3.     #define PI 3.14
  4.     int main()
  5.     {
  6.         printf("%d", sizeof(PI));
  7.     }

a) Output is 8
b) Output is 4
c) Output is 1
d) Error, we can’t use sizeof on macro-definitions
View Answer

Answer: a
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter