Exercise-2 : “integer pointer & array ” combinations

  • Find out the size of elements in each column

Statement

What is this ?

&p

p

*p

p[0]

**p

*p[0]

&p[0]

p[0][0]

&p[0][0]

***p

**p[0]

*p[0][0]

p[0][0][0]

&p[0][0][0]

int p;

int *p;

int **p;

int ***p;

int p[10];

int p[10][10]

int p[10][10][10];

int *p[10];

int *p[10][10];

  • Find out how to store and access data in elements present in below table

Statement

What is this ?

&p

p

*p

p[0]

**p

*p[0]

&p[0]

p[0][0]

&p[0][0]

***p

**p[0]

*p[0][0]

p[0][0][0]

&p[0][0][0]

int p;

int *p;

int **p;

int ***p;

int p[10];

int p[10][10]

int p[10][10][10];

int *p[10];

int *p[10][10];

  • Find out the function prototypes when elements in each column are passed to a function

Statement

What is this ?

&p

p

*p

p[0]

**p

*p[0]

&p[0]

p[0][0]

&p[0][0]

***p

**p[0]

*p[0][0]

p[0][0][0]

&p[0][0][0]

int p;

int *p;

int **p;

int ***p;

int p[10];

int p[10][10]

int p[10][10][10];

int *p[10];

int *p[10][10];

  • Find out elements in each column which can be changed

Statement

What is this ?

&p

p

*p

p[0]

**p

*p[0]

&p[0]

p[0][0]

&p[0][0]

***p

**p[0]

*p[0][0]

p[0][0][0]

&p[0][0][0]

int p;

int *p;

const int *p;

const int *const p;

int **p;

const int **p;

const int *const *p;

const int *const *const p;

int ***p;

const int ***p;

const int *const **p;

const int *const *const *p;

const int *const *const *const p;

int p[10];

int p[10][10]

int p[10][10][10];

int *p[10];

const int *p[10];

const int *const p[10];

int *p[10][10];

const int *p[10][10];

const int *const p[10][10];

  • Learn post-increment, post-decrement, pre-increment, pre-decrement. Assume below set of C statements

    int a[5] = {1,2,3,4,5};
    int *p = &a[2];
    

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

Operation

Memory address

Memory content

*p

*p++

*(p++)

(*p)++

*++p

*(++p)

++*p

++(*p)

p*++

p++*

*p--

*(p--)

(*p)--

*--p

*(--p)

--*p

--(*p)

p*--

p--*

  • Learn array access. Consider a single dimension array : int a[5] = {1,2,3,4,5};

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

Statement

What is this ?

sizeof()

Memory or value ?

a

&a

a[0]

&a[0]

a + 1

*(a + 1)

&(a+1)

a[1]

&a[1]

*(a + 5 - 3)

  • Learn array access. Consider a double dimension array

    int a[3][4] =
    {
    	{1,2,3},
    	{4,5,6},
    	{7,8,9},
    };
    

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

Statement

What is this ?

sizeof()

Memory or value ?

a

&a

a[0]

&a[0]

a + 1

*(a + 1)

&(a + 1)

a[1]

&a[1]

*(a + 5 - 3)

a[1][2]

*(*(a + 1) + 2)

*(a + 1)[2]

*(a[1] + 2)

a[2][1]

*(*(a + 2) + 1)

*(a + 2)[1]

*(a[2] + 1)