Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
#include <stdio.h> int main() { printf(5 + "abhishekdas\n") ; return 0 ; }
程序的输出是hekdas。它是如何工作的?它不应该显示错误吗?怎么可能写类似5 + "abhishekdas"inside printffunction 的东西?
hekdas
5 + "abhishekdas"
printf
5+"abhishekdas\n" ==> "abhishekdas\n"+5 ==> &"abhishekdas\n"[5] ==> "hekdas\n"
5+"abhishekdas"
等价于&"abhishekdas"[5],即数组第六个元素的地址。
&"abhishekdas"[5]
"abhishekdas"是一个字符串字面量:它的类型是一个数组类型。与每个数组对象一样,在表达式中求值时,它会转换为指针类型。5+"abhishekdas"简单的指针算术也是如此。
"abhishekdas"