Hello All,
Looking at the following code sizeof int is hardcoded.
Code:
size = sizeof(i);
0040B840 mov byte ptr [ebp-8],4
I had thought that sizeof operator work similar to the following code.( 5th and 6th printf)
Code:
# include<stdio.h>
main(void)
{
int i;
char character;
int *p = &i;
char *c = &character;
printf("Size of %d\n",p);
printf("Size of %d\n",c);
printf("Size of %d\n",p+1);
printf("Size of %d\n",c+1);
printf("Size of %d\n",p+1-p);
printf("size of %d\n",c+1-c);
printf("Size of %p\n",p+1-p);
printf("size of %p\n",c+1-c);
character = sizeof(i);
printf("Sizeof int = %d\n",character);
}
But looking the above two snaps I am confused.
Please let me know, How sizeof is implemented.
And in above C program, 5th and 6th printf statement prints
1
1
and is still confusing.
I wonder, when - and + operator have same associtivity and at same level, why doesn't it increment first to address four bytes ahead( in case of integer pointer) and substracting same pointer give size of datatype.
Please let me know..
RT