Skip to content
Related Articles
Open in App
Not now

Related Articles

Algorithms Quiz | Sudo Placement : Set 1 | Question 5

Improve Article
Save Article
Like Article
  • Difficulty Level : Hard
  • Last Updated : 28 Dec, 2020
Improve Article
Save Article
Like Article

What will be the output of following C program?

char g[] = "geeksforgeeks";
printf("%s", g + g[6] - g[8]);

(A) geeks
(B) rgeeks
(C) geeksforgeeks
(D) forgeeks

Answer: (A)


char g[] = “geeksforgeeks”;  

// g now has the base address string “geeksforgeeks”  

// 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 “geeks”  

printf(“%s”, g + g[6] – g[8]);  // prints geeks 

Hence, option (A) is correct

Quiz of this Question

My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!