Exercise-3 : “strutures pointer & array ” combinations

  • Learn structure member access. Consider the code snippet below. An integer inside structure
    struct abc {
    	int x;
    };
    
    struct abc a;
    struct abc *p = &a;
    

    What will be the change in memory or value after each of the below operations ?

Statement

What is this ?

sizeof()

Memory or value ?

Actual Arguments

Formal Arguments ?

&a

fun(&a);

a

fun(a);

a.x

fun(a.x);

&a.x

fun(&a.x);

&p

fun(&p);

p

fun(p);

*p

fun(*p);

p[0]

fun(p[0]);

p->x

fun(p->x);

&(p->x)

fun(&p->x);

(*p).x

fun((*p).x);

&((*p).x)

fun(&((*p).x));

  • Learn structure member access. Consider the code snippet below. An integer pointer inside structure
    struct abc {
    	int *x;
    };
    
    struct abc a;
    struct abc *p = &a;
    int q = 5;
    
    a.x = &q;
    

    What will be the change in memory or value after each of the below operations ?

Statement

What is this ?

sizeof()

Memory or value ?

Actual Arguments

Formal Arguments ?

&a

fun(&a);

a

fun(a);

a.x

fun(a.x);

&a.x

fun(&a.x);

*(a.x)

fun(*(a.x));

&p

fun(&p);

p

fun(p);

*p

fun(*p);

p[0]

fun(p[0]);

p->x

fun(p->x);

&(p->x)

fun(&(p->x));

(*p).x

fun((*p).x);

&((*p).x)

fun(&((*p).x));

*(p->x)

fun(*(p->x));

*(&(p->x))

fun(*(&(p->x)));

*((*p).x)

fun(*((*p).x));

*(&((*p).x))

fun(*(&((*p).x)));

  • Learn structure member access. Consider the code snippet below. A single dimension integer array inside structure
    struct abc {
        int x[5];
    } a = { .x = {1,2,3,4,5} }, *p = &a;
    

    What will be the change in memory or value after each of the below operations ?

Statement

What is this ?

sizeof()

Memory or value ?

Actual Arguments

Formal Arguments ?

&a

fun(&a);

a

fun(a);

a.x

fun(a.x);

&a.x

fun(&a.x);

&p

fun(&p);

p

fun(p);

*p

fun(*p);

p[0]

fun(p[0]);

p->x

fun(p->x);

&(p->x)

fun(&(p->x));

(*p).x

fun((*p).x);

&((*p).x)

fun(&((*p).x));

a.x[2]

fun(a.x[2]);

*(a.x + 2)

fun(*(a.x + 2));

(*p).x[2]

fun((*p).x[2]);

p->x[2]

fun(p->x[2]);

*((*p).x + 2)

fun(*((*p).x + 2));

*(p->x + 2)

fun(*(p->x + 2));

a.x[3]

fun(a.x[3]);

*(a.x + 3)

fun(*(a.x + 3));

(*p).x[3]

fun((*p).x[3]);

p->x[3]

fun(p->x[3]);

*((*p).x + 3)

fun(*((*p).x + 3));

*(p->x + 3)

fun(*(p->x + 3));

  • Learn structure member access. Consider the code snippet below. A double dimension integer array inside structure
    struct abc {
        int x[3][4];
    } a = {
            .x = {
                    {1,2,3,4},
                    {5,6,7,8},
                    {9,10,11,12},
                 }
         },
         *p = &a;
    

    What will be the change in memory or value after each of the below operations ?

Statement

What is this ?

sizeof()

Memory or value ?

Actual Arguments

Formal Arguments ?

&a

fun(&a);

a

fun(a);

a.x

fun(a.x);

&a.x

fun(&a.x);

&p

fun(&p);

p

fun(p);

*p

fun(*p);

p[0]

fun(p[0]);

p->x

fun(p->x);

&(p->x)

fun(&(p->x));

(*p).x

fun((*p).x);

&((*p).x)

fun(&((*p).x));

a.x[2]

fun(a.x[2]);

*(a.x + 2)

fun(*(a.x + 2));

(*p).x[2]

fun((*p).x[2]);

p->x[2]

fun(p->x[2]);

*((*p).x + 2)

fun(*((*p).x + 2));

*(p->x + 2)

fun(*(p->x + 2));

a.x[3]

fun(a.x[3]);

*(a.x + 3)

fun(*(a.x + 3));

(*p).x[3]

fun((*p).x[3]);

p->x[3]

fun(p->x[3]);

*((*p).x + 3)

fun(*((*p).x + 3));

*(p->x + 3)

fun(*(p->x + 3));

a.x[2][1]

fun(a.x[2][1]);

(*(a.x + 2))[3]

fun((*(a.x + 2))[3]);

*(*(a.x + 2) + 1)

fun(*(*(a.x + 2) + 1));

p->x[2][1]

fun(p->x[2][1]);

(*p).x[2][1]

fun((*p).x[2][1]);

(*(p->x + 2))[3]

fun((*(p->x + 2))[3]);

(*((*p).x + 2))[3]

fun((*((*p).x + 2))[3]);

*(*(p->x + 2) + 1)

fun(*(*(p->x + 2) + 1));

*(*((*p).x + 2) + 1)

fun(*(*((*p).x + 2) + 1));

*(*(p->x))

fun(*(*(p->x)));

*(*((*p).x))

fun(*(*((*p).x)));