相关疑难解决方法(0)

当我在printf()中的字符串后面添加带加号的int时会发生什么

我已经在一个混淆程序中读了下面的代码.

我想知道为什么编译器在我这样做时给了我一个警告而不是一个错误.代码真正想做什么以及为什么编译器建议我使用数组?

#include <stdio.h>
int main()
{
    int f = 1;
    printf("hello"+!f);
    return 0;
}

warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
printf("hello"+!f);
       ~~~~~~~^~~
note: use array indexing to silence this warning
printf("hello"+!f);
              ^
       &      [  ]
Run Code Online (Sandbox Code Playgroud)

c printf

1
推荐指数
1
解决办法
495
查看次数

标签 统计

c ×1

printf ×1