I am testing the sizeof operator. In two cases in my code, I get the size of the pointer (I think). In the other cases I get how many bytes the arrays occupy. How can I get the size of the array in bytes when I pass it to a function? Isn't the sizeof operator enough? Am I doing something wrong?
#include <stdio.h>
/*Testing the operator sizeof*/
void test (char arrayT[]);
void test2 (char *arrayU);
int main(int argc, char *argv[]){
char array1[7];
printf("array1 size is:%d\n", sizeof array1);
/*array1 size is: 7*/
char array2[] = { '1', '2', '3', '4', '5', '6', '7'};
printf("array2 size is:%d\n", sizeof array2);
/*array2 size is: 7*/
char array3[] = "123456";
printf("array3 size is:%d\n", sizeof array3);
/*array3 size is: 7*/
unsigned char array4[] = "123456";
printf("array4 size is:%d\n", sizeof array4);
/*array4 size is: 7*/
char arrayX[] = "123456";
test(arrayX);
/*arrayT size is: 4*/
char arrayY[] = "123456";
test2(&arrayY[0]);
/*arrayU size is: 4*/
return 0;
}
void test (char arrayT[]){
printf("arrayT size is:%d\n", sizeof arrayT);
}
void test2 (char *arrayU){
printf("arrayU size is:%d\n", sizeof arrayU);
}