I was trying to differentiate integer pointer and integer array pointer and here's the code that I am using as an example:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ZLEN 5
typedef int zipdig[ZLEN] ;
#define UCOUNT 3
typedef int (*row5_pt)[ZLEN];
int main(int argc, char *argv[]) {
zipdig cmu = {8, 5, 2, 1, 3};
zipdig mit = {0, 2, 1, 3, 9};
zipdig ucb = {9, 4, 7, 2, 0};
int *univ[UCOUNT] = {mit, cmu, ucb};
int result1 = *univ[1];
row5_pt pt[UCOUNT] = {&mit, &cmu, &ucb};
int result2 = (*pt[1])[1];
printf("\nresult is %d \n", result1);
printf("\nthe size of dereferenced univ is %lu bytes \n", sizeof(*univ[1]));
printf("\nresult is %d \n", result2);
printf("\nthe size of dereferenced pt is %lu bytes \n", sizeof(*pt[1]));
return 0;
}
At first I am confused at the following two assignment:
int *univ[UCOUNT] = {mit, cmu, ucb};
row5_pt pt[UCOUNT] = {&mit, &cmu, &ucb};
here univ is an array of 3 integer pointers, and pt is an array of pointers that point to a 5-element int array. And my confusion is that in the first assignment, mit, cmu and ucb, these array identifiers are regarded as pointers, but when it comes to second assignment, why mit, cmu and ucb are regarded as array, not pointers?
Later I realized that this is due to the different pointer type that I use: the first assignment, the element of univ is an integer pointer, and mit, cmu, ucb are exactly regarded as integer pointer, but for second assignment, the element of pt is a pointer pointing to array, not integers, thus we could not directly use mit, cmu or ucb but have to use their address instead.
Is my understanding correct?