sizeof is an operator (operator) in C/s + + that returns the number of bytes of memory that an object or type occupies. The return value type is size_t and is defined in the header file stddef.h.
sizeof of pointer variables (unlike arrays): equal to the width of the internal address bus select、read of the computer. So in a 32-bit computer, the return value of a pointer variable must be 4 (note that the result is in bytes), and the sizeof result of the pointer variable in the 64-bit system is 8.
Suppose there is a code fragment:
Char *aa; int *bb;
void *cc;
printf ("aa=%d, bb=%d, cc=%d, sizeof int=%d\n", sizeof AA, sizeof BB, sizeof cc, sizeof (int));
On a 64-bit system, the results are 8.
Suppose there is a code fragment:
int a[]={1,2,3,4,5};
int i;
For (I=-1;i<sizeof (a)/sizeof (a[0]); i++)
printf ("%d", a[i]);
What is the number of cycles?
Should be 0 times, the crux of the matter is the sizeof return value type, is a size_t type, and size_t is defined, typedef unsigned int size_t, that is, it is a unsigned int type. Therefore, when executing i<sizeof (a)/sizeof (a[0]), I is converted to the unsigned int, so I is greater than sizeof (a)/sizeof (a[0)) it, all not performing loops.