请问有人能告诉我c语言中的内存分配吗? char类型变量的大小是多少?2还是4? 为什么数组中相邻的两个字符元素之间地址值只相差1呢?
char foo [] = {'a', 'b'};
printf ("This is the Address of val1 %d \n", &foo[1]); // -1079295441
printf ("This is the Address of val2 %d \n", &foo[2]); // -1079295440
printf ("The size of each array member is %d \n", sizeof(foo)); // 2
foo
是一个字符数组,因此与任何其他数组具有相同的大小,因为它本质上只是一个指针。 - apokryfos