There is something I can't understand in c
.
The following code:
#include <stdio.h>
int main(char* args){
char abc[100];
printf("%d %d", sizeof(abc), sizeof(abc+1));
}
outputs
100 4
I tought it should generate 100 100-1
, which is:
100 99
Same for int abc[100]
.
It outputs
400 4
instead of
400 396
edit:
Ok, so I saw your commands. abc+1 in an expression. therfore, the result is int, sizeof(int) == 4
. So my other question is WHY in the first time I send a pointer for array and the result is the length of the array?
The following:
int main(char* args){
char abc[100];
char *test;
test = (char*)abc+1;
printf("%d %d", sizeof(abc), sizeof(test));
}
Outputs
100 4