ProgrammingHardTCS 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)? #include <stdio.h> #include <string.h> int main(void) { char s[] = "laptop"; s[1] = '\0'; printf("%zu %zu %s", strlen(s), sizeof(s), s + 0); return 0; }
- A. 1 7 laptop
- B. 1 7 l
- C. 2 7 la
- D. 1 6 l
Correct answer: B. 1 7 l
s[1] = '\0' ends the string after 1 characters, so strlen = 1; sizeof still reports the array size 7 (including the original terminator); printf("%s") prints "l".
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)? #include <stdio.h> int…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h>…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…
- What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits)? #include <stdio.h> int…