Open In App

Algorithms Quiz | Sudo Placement : Set 1 | Question 5

Like Article
Like
Save Article
Save
Share
Report issue
Report

What will be the output of following C program?

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

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


Answer: (A)

Explanation:

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


Last Updated : 28 Dec, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads