Problem with simple function in C
I am new in C and I have problem with compiling this code.
#include <stdio.h>
void suma( int a, int b, int wynik)
{
wynik=0;
printf("a=\n");
scanf("%d",&a);
printf("b=\n");
scanf("%d",&b);开发者_JAVA百科
wynik=a+b;
printf("wynik = %d",&wynik);
}
int main()
{
suma(int a, int b, int wynik);
}
I don't know why but compiler tells me that 2 argument has type int * insted of int. I dont' know what does it mean and where I made mistake.
Change
printf("wynik = %d",&wynik);
to
printf("wynik = %d",wynik);
Otherwise you'll be printing the address of wynik
as an integer.
Also the way you call suma
makes no sense.
change printf("wynik = %d",&wynik);
to printf("wynik = %d",wynik);
and also you don't seem to need the arguments of suma.
Try this:
void suma()
{
int a,b,wynik;
wynik=0;
printf("a=\n");
scanf("%d",&a);
printf("b=\n");
scanf("%d",&b);
wynik=a+b;
printf("wynik = %d",wynik);
}
int main()
{
suma();
}
精彩评论