incompatible pointer type

2

Hello, programming / studying the language, C, I came across the following error

warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
 int *ponteiro = &x;

Being the code:

#include <stdio.h>

void main(){

int x[] = {0,1, 2, 3, 4, 5, 6,7,8,9,10};
int *ponteiro = &x;

 for (int i = 0; i < 11; i++){
        printf("%i\n", *(ponteiro++));
    }
}

How can I resolve this error?

    
asked by anonymous 26.12.2018 / 03:48

1 answer

2

When you declare x [] x it can be considered as a pointer. When it does:

int *ponteiro = &x;

In fact you are assigning the address of the address.

In your case, do:

int *ponteiro = x;
    
26.12.2018 / 03:53