Assign appropriate variables so that these declarations are correct

I was provided with the following code:

int TAB[4][6];
int (*FF(int k))[3];
char *NAP[]={"nap1", "nap2", "nap3"};
double T[][2]={{1.0,1.0},{0.},{2.0,3.0}};

and I have to make these declarations correct (so that they do not return any errors in the compiler):

a = &T;
b = FF;
c = FF(9);
d = TAB[2];
e = FF(9)[1];
f = *NAP+1;
g = *NAP[1]++;

I only managed to do a few. My compiler (xCode) did not return any errors for them, but I have no idea how to declare the remaining 3 ...

What I managed to do:

1.int (*c)[3]= FF(9); 
2.int *d = TAB[2];
3.char *f = *NAP+1;
4.char g = *NAP[1]++;
  • The function FFreturns a pointer to a 3-element array, so do we need a pointer to a 3-element array?
  • Since it TAB[2]is the second subarray, just a pointer is enough?
  • *NAP+1points to the address of the character of the "a"first word in the array NAP, so do we need a pointer to store this address?
  • *NAP[1]++ , ?
+4
1

, , : . cdecl, .

:

cdecl> explain double T[][2];
declare T as array of array 2 of double

, double T[][2]; T 2 double. & -, -. , &T a, a 2 double:

cdecl> declare a as pointer to array of array 2 of double;
double (*a)[][2]

FF:

cdecl> explain int (*FF(int))[3];
declare FF as function (int) returning pointer to array 3 of int

FF . , , . - :

cdecl> declare b as pointer to function (int) returning pointer to array 3 of int
int (*(*b)(int ))[3]

c, FF (int), 3 int, FF int (9) , 3 int:

cdecl> declare c as pointer to array 3 of int
int (*c)[3]

e , lvalue 3 int. , lvalues ​​ , 3 int int. , , int, , cdecl:

cdecl> declare e as pointer to int;
int *e;

, , :

int TAB[4][6];
int (*FF(int k))[3];
char *NAP[]={"nap1", "nap2", "nap3"};
double T[][2]={{1.0,1.0},{0.},{2.0,3.0}};

int main(void) {
    double (*a)[][2];
    int (*(*b)(int ))[3];
    int (*c)[3];
    int *d;
    int *e;
    char *f;
    char g;

    a = &T;
    b = FF;
    c = FF(9);
    d = TAB[2];
    e = FF(9)[1];
    f = *NAP+1;
    g = *NAP[1]++;
}
+4

Source: https://habr.com/ru/post/1680365/


All Articles