Hi there,
The first sample program that I am reading on the book has the following code:
When I compile it using the gcc compiler, it gives the error:Code:* Demonstrates basic pointer use. */ #include <stdio.h> /* Declare and initialize an int variable */ int var = 1; /* Declare a pointer to int */ int *ptr; int main( void ) { /* Initialize ptr to point to var */ ptr = &var; /* Access var directly and indirectly */ printf("\nDirect access, var = %d", var); printf("\nIndirect access, var = %d", *ptr); /* Display the address of var two ways */ printf("\n\nThe address of var = %d", &var); printf("\nThe address of var = %d\n", ptr); return 0; }
Is this a compiler error or is there a proper syntax for pointers using the gcc compiler?ptr.c: In function ‘main’:
ptr.c:26:5: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat]
ptr.c:27:5: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat]
Thanks



LinkBack URL
About LinkBacks



