以下C程序的输出是什么?
main()
{
char g[] = "geeksforgeeks";
printf("%s", g + g[6] - g[8]);
}
(一)极客
(B)怪胎
(C)极客
(D)极客答案: (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
因此,选项(A)是正确的
这个问题的测验