格式'%d'需要类型为'int'的参数,但参数2的类型为'int*'

use*_*334 0 c printf

我正在使用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)

Sti*_*sis 5

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需要修改该值.)