GATE 2015 CS (CS3) – Question 11
What is printed?
#include <stdio.h>
int main(void) {
char s1[7]="1234", *p;
p=s1+2;
*p='0';
printf("%s",s1);
}Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (C) 1204
Explanation
The pointer p addresses index two, initially the character three. It is replaced by the digit character zero, not the string terminator. The characters become one,two,zero,four followed by the original terminator. Thus the printed string is 1204, C.