Pointer to array of integer in c




Pointer to array of integers: A pointer to such an array which contents are integer numbers is known as pointer to array of integer.


What will be output if you will execute following code?

#include<stdio.h>

int main(){

static int i,j,k;
int *(*ptr)[];
int *array[3]={&i,&j,&k};

ptr=&array;
j=i+++k+10;
++(**ptr);

printf("%d",***ptr);

return 0;
}

Output: 10

Explanation:

In this example:

array []: It is array of size three and its content are address of integer.

ptr: It is pointer to array which content are address of integer.

Pictorial representation above declaration:






Note: In the above figure upper part of box represent content and lower part represent memory address. We have assumed arbitrary address.

j=i+++k+10
=i++ + k+10
=0 +0 +10=10

***ptr = *** (&array) //ptr=&array
= **array //From rule *&p=p
//From rule array [0] =*(array+0) and ++ (**ptr)
=*array [1]
=*&j
=j
=10


What will be output if you will execute following code?

#include<stdio.h>

int main(){

int i,j,k;
int *(*ptr)[];
int *array[3]={&i,&j,&k};

ptr=&array;
j=i+++k+10;
++(**ptr);

printf("%d",***ptr);

return 0;
}

Output: Compiler error
Explanation: Address of auto variable cannot be member of an array.



Pointer to array of pointer to string
Pointer to three dimentional array
Pointer to two dimensional array
Sorting of array using pointer
Pointer to array of array
Pointer to array of union
Pointer to array of structure
Pointer to array of character
Pointer to array of integer
Complex pointer
Generic pointer
Null pointer

C tutorial
Post a Comment