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; }
- A. 1
- B. Unspecified, but commonly 1 due to string literal pooling
- C. Compilation error
- 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
- 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…
- 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…
- 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…
- 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…
- 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…
- 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…