Hello,
I'M a newbie C programming,i read book to learn C,in chapter of pointers and arrays, written an example that i write :
output this code is all of tests elements.Code:#include <stdio.h> void main() { char test[3][3] = {{4,5,1},{6,9,7},{3,2,8}}; for(int i = 0;i<9;i++){ printf("%d\n",*(*test + i)); } }
in the line printf("%d\n",*(*test + i)); , in section (*test + i) in section c in each loop i addition to address of first byte of test array.t type is char and each element have 1 byte,thus when address of first byte addition to i,in each loop we go to the next element of array.i changed type of test to int,and compiled this sample again, when type of test is int each element have 4 bytes,thus when *test + i we shouldn't go to next element,but when i printf address of *test + i, i saw the address grows 4 bytes !!
why after i change type of test,when i addition i to *test, address grows 4 bytes ?
i can't understand what happened
excuse me for my bad english .
thanks in advance .



7Likes
LinkBack URL
About LinkBacks






. A book can however give a basis .