I was experimenting with array and pointers in C. And here
http://r4r.co.in/c/c_topics/c_array_basics/array_representation_in_memory.shtml
I read that
ar[2]=*(ar+(sizeof(datatype)*2));
However after writing following test program in C:-
#include<stdio.h>
#include<conio.h>
int main()
{
int array[]={10,11,12,13,14};
printf("\nArray:%d",array);
printf("\nArray+4:%p",array+4);
printf("\nArray+(sizeof(int)*4):%p",array+((sizeof(int))*4));
printf("\n*(Array+4):%d",*(array+4));
printf("\n*(Array+(sizeof(int)*4)):%d",*(array+((sizeof(int))*4)));
getch();
return 0;
}
I get following output:-
Array:2686700
Array+4:0028FEFC
Array+(sizeof(int)*4):0028FF2C
*(Array+4):14
*(Array+(sizeof(int)*4)):4214784
So from here I concluded that the expression
array[4]=*(array+(sizeof(int)*4));
is not working rather expression
array[4]=*(array+4);
is true.
So is my conclusion right or wrong? If it is wrong then why is that so?
Language:-C Version:-gcc (tdm-1) 4.7.1 Platform:-Windows 8.1
Edit:
1). Changed following lines:
((sizeof(int*))*4
to ((sizeof(int))*4
2). Changed title to : Various ways of array representation using pointers in C.
3). Fixed grammar.