Data type warning when initializing pointers

I'm currently trying to wrap my head around pointers to C based on interfaces, which is not an easy task. I follow this tutorial and everything works smoothly until I try to compile the following example:

#include <stdio.h>

int main(int argc, char *argv[]) {
    int **ramon;
    int *paul;
    int melissa = 5;
    paul = &melissa;
    ramon = &paul;
    printf("ramon = %d\n", ramon); // <- warning: format '%d' expects type 'int'...
    printf("&paul = %d\n", &paul); // <- warning: format '%d' expects type 'int'...
    printf("*ramon = %d\n", *ramon); // <- warning: format '%d' expects type 'int'...
    printf("&melissa = %d\n", &melissa); <- warning: format '%d' expects type 'int'...
    printf("**ramon = %d\n", **ramon);p1); <- warning: format '%d' expects type 'int'...
    return(0);  
}

From the first line of printf I get this error: "warning: format"% d "expects type" int ", but argument 2 is of type" int ** ""

I believe that this is due to the way I initialize my pointers, but standing at the bottom of a steep learning curve, I don’t know how to move forward. What's wrong, how do I initialize pointers to avoid warnings?

+3
source share
8

. , int** (.. int) %d, int.

int

melissa (.. 5), , ramon, .

*, ", ".

  • (.. *ramon) int*, ramon.
  • int, int*.
  • de-reference , , :

    printf("ramon = %d\n", **ramon);

(.. ), %p. :

printf("ramon = %p\n", ramon); // Print the "pointer to the pointer to melissa"
printf("ramon = %p\n", *ramon); // Print the "pointer to melissa"
+4

ramon int, int. ** ramon int. int % d, , % p.

+1

man printf. , , ramon, ramon, int. .

+1

ramon - int **, %d int. *ramon int *, **ramon int.

, %p.

+1

ramon paul - , printf ( , ) - %p.

printf("ramon = %p\n", ramon);
+1

, , printf %d , .

, %p.

+1

ramon " int". " int". %d , int, . :

printf("&paul = %p\n", ramon);     //print the address that ramon points to
printf("&melissa = %p\n", *ramon); //print the address that paul points to
printf("&melissa = %p\n", paul);   //same as above
printf("melissa = %d\n", **ramon); //print the contents of melissa
printf("melissa = %d\n", *paul);   //same as above
printf("melissa = %d\n", melissa); //same as above

&paul = 0xbf8072f4
&melissa = 0xbf8072f0
&melissa = 0xbf8072f0
melissa = 5
melissa = 5
melissa = 5
+1

, ,

, , ? :

"warning: format '%d' expects type 'int', but argument 2 has type 'int **'"

%d printf() , . %d int s. , , ramon. int**. int int** .

, , . %p.

, , .

- / . . - , , (.. ).

0
source

Source: https://habr.com/ru/post/1780552/


All Articles