I have an error code I do not understand:
format %d expects type int, but argument 2 has type int * I do not know the difference between int and int *. I did not know there were different types of int, and cannot find any note of it on webpages about printf and scanf key letters.
The code is as follows:
#include <stdio.h> #include <math.h> int main(void) { int X = 0, Y = 0, A = 0, D = 0; printf("This program computes the area of a rectangle "); printf("and its diagonal length."); printf("Enter Side 1 dimentions: "); scanf("%d", &X); printf("Enter Side 2 dimentions: "); scanf("%d", &Y); /* Calc */ A = X * Y; D = pow(X,2) + pow(Y,2); D = pow(D, 1 / 2); /* Output */ printf("Rectangle Area is %d sq. units.", &A); printf(" Diagonal length is %d.", &D); return 0; } The error references the last two printf's:
printf("Rectangle Area is %d sq. units.", &A); printf(" Diagonal length is %d.", &D); Additionally, this program was originally written using floats (declaring X,Y,A, and D as float and using %f). But that gave an even stranger error code:
format %f expects type double, but argument 2 has type float *
I knew that %f is used for doubles and floats, so I could not understand why I had this error. After I got the error code about floats/doubles I tried changing everything to int (as shown in the above code), just to check. But that delivered the error code at the top of this post, which I do not understand either.
I've been using the gcc compiler. Would someone explain what's being done wrong?
intandint *, notintandint...intis an integer type.int*is a pointer type. An object of typeintcontains an integer value. An object of typeint*contains the address of some object of typeint(or a null pointer that doesn't point to anything).