SSC IMD SA Mock 02 – Question 144

Question:

In C programming, what is the output of printf("%d", sizeof('A')); on a standard 32-bit/64-bit GCC compiler?
C प्रोग्रामिंग में एक मानक 32-बिट/64-बिट GCC कंपाइलर पर printf("%d", sizeof('A')); का आउटपुट क्या होता है?

Options:

  • 4 (character constants are treated as int in C)
  • 1 (since a character is 1 byte)
  • 2
  • Undefined behavior
  • 4 (C में कैरेक्टर स्थिरांक को int माना जाता है)
  • 1 (चूंकि एक कैरेक्टर 1 बाइट का होता है)
  • 2
  • अपरिभाषित व्यवहार

Correct Answer: a)

Explanation:

In C, character literals like 'A' have type int, so sizeof('A') equals sizeof(int), which is 4 bytes. (Note: in C++, character literals have type char and evaluate to 1).
C भाषा में कैरेक्टर लिटरल्स (जैसे ‘A’) का प्रकार int होता है, अतः इसका आकार 4 बाइट्स आता है। (C++ में यह 1 बाइट होता है)।

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top