Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. What does the following fragment of C-program print?
    char c[] = “GATE 2011”
    char * p = c;
    printf (“%s”, p + p[3] – p[1];
    1. GATE 2011
    2. E 2011
    3. 2011
    4. 011
Correct Option: C

2011 charc[] = "GATE2011";
p now has the base address string "GATE2011"
char*p =c;
p[3] is 'E' and p[1] is 'A'.
p[3] - p[1] = ASCII value of 'E' - ASCII value of 'A' = 4
So the expression p + p[3] - p[1] becomes p + 4 which is base address of string "2011



Your comments will be displayed only after manual approval.