Compile and execute under 64-bit Linux system the output of the program is
40 8
#include <stdio.h> #include <stdlib.h> #include <stdint.h>void print_size (int32_t array[10]) {printf ("%ld\n", sizeof (array));} int main () { int32_t myarray[10]; printf ("%ld\n", sizeof (myarray)); Print_size (myarray); return 0;}
Int32_t,int64_t is a pre-defined type of C language to be able to run the program uniformly in different systems, and it is included in the header file stdint.h. They are all int types, except that their bytes remain the same in different systems, for example: int32_t occupies 4 bytes in a 32-bit system, and still accounts for 4 bytes in 64-bit systems. This ensures that the same bytes are consumed in different systems. The specific conversion process does not need to be considered, interested students can go to the head file to see. Int64_t the same truth.
For the above program is compiled on a 64-bit Linux system to run, so int32_t is still bit 4 bytes, so the first result of printing is 40, however, when the function is called the address, the address in the 64-bit system occupies a byte 8 bits, so the result of the second printing is 8.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Compiled int32_t for 64-bit Linux systems