GATE | GATE-CS-2015 (Set 3) | Question 65

Consider the following C program segment.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


What will be printed by the program?

(A) 12

(B) 120400
(C) 1204
(D) 1034


Answer: (C)

Explanation:

    char s1[7] = "1234", *p;
    p = s1 + 2;    // p holds address of character 3
    *p = '0' ;   // memory at s1 + 3 now becomes 0
    printf ("%s", s1);  // All characters are printed


Quiz of this Question

My Personal Notes arrow_drop_up