Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct syntax for initialization of a pointer to an array

Tags:

c

pointers

How can I initialize pointer to an array in C correctly

Here is my code

int (*data[10]);
int a[10];
data = &a[0]; /* gives a warning "int *" cannot be assigned to entity of "int (*)[10]" */

How can I get rid of this warning?

like image 962
user2314818 Avatar asked Feb 17 '23 17:02

user2314818


1 Answers

  1. Declare a pointer to an array correctly:

    int (*data)[10];
    
  2. Assign a pointer to an array to it:

    int a[10];
    data = &a;
    
like image 120
Jonathan Leffler Avatar answered May 13 '23 05:05

Jonathan Leffler