📜  算法测验| Sudo放置:设置1 |问题5

📅  最后修改于: 2021-06-28 22:48:35             🧑  作者: Mango

以下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)是正确的
这个问题的测验