Last Updated : 13 Nov, 2018

Consider the following C program;

#include

int main() {

char s[] = \”GATE2019\”;
printf(\”%s\”, s + (int)(s[4]-\’0\’) – 2*(int)(s[6] – \’0\’));

return 0;
}

What will be the output for above code?

(A) GATE2019
(B) GATE2019EA
(C) ATE2019
(D) 2019


Answer: (A)

Explanation: \"\"
S + S[4] – 2 * S[6] = 1000 + ascii value of (s[4]-\’0\’) – 2 * ascii value of (s[6] – \’0\’)
= 1000 + 2 – 2 = 1000

String at 1000 will be the original string, i.e, GATE2019 will be printed.

So, option (A) is correct.

Quiz of this Question


Share your thoughts in the comments