Similar questions 2 more →
Arrays & Strings
![Question 11, GATE 2015: What does this C program print?
#include <stdio.h>
int main() { char s1[7]="1234", *p; p=s1+2; *p='0'; printf("%s",s1); }
The assigned character is digit '0', not the null character '\0'. Options: (A) 12; (B) 120400; (C) 1204; (D) 1034.](../../assets/questions/CS-2015-S3-Q11-1.webp)
Your answer
Answer & solution
Official answer: C
Step through it (8 steps)
1. Initially the character array begins with 1,2,3,4 followed by a null terminator. Pointer arithmetic advances by characters, so s1+2 selects the third stored character. The assignment changes that position only; printf with %s stops at the unchanged original terminator.
2. p points to s1[2]. Assigning character'0' replaces digit 3, not the terminating null byte. The string becomes 1204 followed by its original terminator, so C.