Pointer to two dimensional array in c programming

a
Examples of pointers to 2 dimensional array:

What will be output if you will execute following code?

#include<stdio.h>
void main(){

long array[][3]={7l,14l,21l,28l,35l,42l};
long int (*ptr)[2][3]=&array;

printf("%li ",-0[1[0[ptr]]]);

return 0;
}

Output: -28

Explanation:

-0[1[0[ptr]]]
=-1[0[ptr]][0] //From rule array[i]=i[array]
=-0[ptr][1][0]
=-ptr [0] [1] [0]
=-*ptr [0] [1] //From rule array[i]=*(array+i)
=-*(&array) [0] [1]
=-(&array) [0] [1][0]
=-(*&array)[1][0] //From rule *&p=p
=-array[1][0]

array[1][0] means 1*(3)+ 0 = 3rd element of array starting from zero i.e. 28

Pointer to function
Pointer to array of function
Pointer to array of string
Pointer to structure
pointer to union
Multi level pointer
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
C tutorial

2 comments:

padam said...

why 28 not 281????

jayesh sidhwani said...

That is 28(L) L for long and not 281