Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - C program, strlen is to find the length of the string, if it is an integer array, what is it? There is also the problem of shaping arrays into function parameters?
C program, strlen is to find the length of the string, if it is an integer array, what is it? There is also the problem of shaping arrays into function parameters?
The principle of strlen function to find the length of string is: read byte by byte from the start address and stop reading until' \0' (that is, 0).

int a[2]={2,3 }; The two elements of a account for 8 bytes: 0x00 0x00 0x00 0x00 0x00 0x00 0x00.

Then strlen(a) starts at 0x02 and ends at 0x00, so the length 1 is returned. If a[0] is assigned to 257, it will return 2, a[0] to 65793, it will return 3, and A [0] to 16843009, it will return.

The array as a function parameter is just a pointer, and the length of a 32-bit system is 4.

a =(int *)malloc(2);

printf("%d\n ",strlen(a)); This result is uncertain. The value of *a is random, and the value in the address after a is also random. Strlen will read from A until it reaches 0. In your example, the18th byte after reading A is 0, so it returns 17.