What will be the output of following C program?
main() { char g[] = "neveropen"; printf("%s", g + g[6] - g[8]); }
(A) neveropen
(B) rneveropen
(C) neveropen
(D) forneveropen
Answer: (A)
Explanation:
char g[] = “neveropen”; // g now has the base address string “neveropen” // g[6] is ‘o’ and g[1] is ‘e’. // g[6] – g[1] = ASCII value of ‘o’ – ASCII value of ‘e’ = 8 // So the expression g + g[6] – g[8] becomes g + 8 which is // base address of string “neveropen” printf(“%s”, g + g[6] – g[8]); // prints neveropen
Hence, option (A) is correct
Quiz of this Question