Skip to content
Related Articles

Related Articles

Improve Article

GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 36

  • Last Updated : 26 Dec, 2019

What should be input string in order to get output “GATE2019” in given C program?




#include <stdio.h>
  
  int main() {
    char string[] = "________"; // your input string
    char * ptr = string;
    * ptr = * ptr + 4;
    ptr = ptr + 3;
    printf("%c", * ptr);
    ptr++;
    printf("%c", * ptr);
    ptr = string;
    printf("%c", * ptr);
    ptr++;
    printf("%c", * ptr);
    printf("%d", 2019);
    return 0;
  }

(A) PETAGe
(B) EPeGAT
(C) PEeGAT
(D) PETAGe


Answer: (C)

Explanation:




#include <stdio.h>
  
  int main() {
    char string[] = "PEeGAT";
    char * ptr = string;
    * ptr = * ptr + 4;
    ptr = ptr + 3;
    printf("%c", * ptr);
    ptr++;
    printf("%c", * ptr);
    ptr = string;
    printf("%c", * ptr);
    ptr++;
    printf("%c", * ptr);
    printf("%d", 2019);
    return 0;
  }

Option (C) is correct.

Quiz of this Question

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.




My Personal Notes arrow_drop_up
Recommended Articles
Page :