ProgrammingVery hardTCS NQT · Infosys · Product Company SDE

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> #include <string.h> int main(void) { char *s1 = "hello"; char *s2 = "hello"; printf("%d", s1 == s2); return 0; }

  1. A. 1
  2. B. Unspecified, but commonly 1 due to string literal pooling
  3. C. Compilation error
  4. D. 0

Correct answer: B. Unspecified, but commonly 1 due to string literal pooling

Whether identical string literals share storage is implementation-defined; most compilers pool/merge identical read-only literals, so s1==s2 often prints 1, but the language does not guarantee it.

More C Programming questions

Exams that ask this topic