type of incompatible pointer

Asked

Viewed 81 times

3

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 fix this mistake ?

1 answer

3


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

int *ponteiro = &x;

in reality is assigning the address of the address.

In your case do:

int *ponteiro = x;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.