I am struggling with pointers concept of C, precisely with Array of pointers. See the below program for reference.
#include <stdio.h>
int a1[] = {6,7,8,18,34,67};
int a2[] = {23,56,28,29};
int a3[] = {-12,27,-31};
int *x[] = {a1,a2,a3};
void print (int *a[]){
printf ("%d",a[0][2]);
printf ("%d",*a[2]);
printf ("%d",*++a[0]);
printf ("%d",*(++a)[0]);
printf ("%d",a[-1][1]);
}
void main (){
print (x);
}
what I don't understand is, if we are passing int *a[]
as an array of pointers, it should be an array after all right ? but I'm being told that here a is only a single pointer variable which acts as an alias to x but according to the syntax a should be an Array, ie. the activation record of print()
function should contain an array not merely a pointer variable that holds the base address of x but that's the whole confusion is it a pointer or an array of pointers, the syntax surely suggests that it should be an array of int
pointers, I read online but got way more confused, please don't disregard this question by flagging irrelevant.