我正在使用Linux,当我尝试使用此代码显示时:
#include <stdio.h>
#include <math.h>
int main()
{
int a,b,c;
int result;
printf( "How Many Times Would You Like to Add: ");
scanf( "%d", &a );
//getchar();
printf( "What Number Would You Like to Add: ");
scanf( "%d", &b );
//getchar();
printf( "What Number Would You Like to Add to It?: ");
scanf( "%d", &c );
//getchar();
for( int $i = 0; $i < a; $i++ )
{
result = b + c;
printf( "%d", &result );
printf( "\n" );
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我明白了:
main.c: In function ‘main’:
main.c:26:3: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat]
Run Code Online (Sandbox Code Playgroud)
使用此编译命令:
cd ./TSTS
gcc -std=c99 main.c -o LetsADD!
Run Code Online (Sandbox Code Playgroud)
for( int $i = 0; $i < a; $i++ )
Run Code Online (Sandbox Code Playgroud)
删除$这里.这不是PHP.
printf( "%d", &result );
Run Code Online (Sandbox Code Playgroud)
删除&这里.printf取值,而不是指针.&获取变量的地址.(注意,scanf 确实需要一个指针,因为C使用pass-by-value,scanf需要修改该值.)
| 归档时间: |
|
| 查看次数: |
12192 次 |
| 最近记录: |