Eight Techniques to Print 2-D Array Elements Using Pointer in C Programming Language

Pubblicato il: 12 ottobre 2020
sul canale di: Ashoksinh Zala Academy
15
0

There are four techniques to assign pointer variable to 2-D Array
1. p=&x[0][0]; or 2. p=*x; or 3. p=&x[0]; or p=x;

There are eight techniques to print 2-D Array elements using pointer as following: 1. x[i][j] 2. *(x[i]+j) 3. *(*(x+i)+j) 4.*(i[x]+j) 5. *(*(i+x)+j) 6. *p
7. *(p+i*3+j) 8. *(p+3*i+j)
int x[3][3]={{1,2,3},{4,5,6},{7,8,9}},*p;
2-D Array is collection of 1-D Array as following:
0 row 1 row 2 row
First 1-D Array Second 1-D Array Third 1-D Array
x 1 2 3 4 5 6 7 8 9
1000 1002 1004 1006 1008 1010 1012 1014 1016
p=x store 1000 Address
p+1 store 1006 Address
p+2 store 1012 Addreess

pointer increment then swift 1-D Array first element as following formula:
suppose find address of second 1-D Array x[1][0]

p=Basic Address+(index*scale factor of total 1-D Array size);
=1000+(1*3)
=1000+(3)
=1006 because pointer datatype 1-D Array required six bytes of memory and you know that integer data type 2 bytes store their value. scale factor refer the data type to no .of byte to swift to pointer variable here integer data type 1- row required six bytes, so very p++ swift six bytes increment their address base above formula.
second formula to find particular element address as following :
Array variable name=(Base Address + row no. *no. of columns + column no.)
suppose find address of x[1][1]; so put value to formula as following :
x[1][1]=(1000+1*3+1)
x[1][1]=(1000+4) pointer refer the data type of integer so 4*2 =8
x[1][1]=(1008) their value is 5 store that address
any value you can find base on this formula.


In questa pagina del sito puoi guardare il video online Eight Techniques to Print 2-D Array Elements Using Pointer in C Programming Language della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Ashoksinh Zala Academy 12 ottobre 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 15 volte e gli è piaciuto 0 spettatori. Buona visione!