The GATE Grind

GATE 2015 CS (CS3) – Question 11

Programming and Data Structures · Programming in C · 1 mark · Multiple choice

What is printed?

#include <stdio.h>
int main(void) {
 char s1[7]="1234", *p;
 p=s1+2;
 *p='0';
 printf("%s",s1);
}
  1. 12
  2. 120400
  3. 1204
  4. 1034

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.

More Programming in C questions

All Programming in C questions →