size of character array and size of character pointer

sizeof an array is the size of the total array, in the case of "bobby", it's 5 characters and one trailing \0 which equals 6.

sizeof a pointer is the size of the pointer, which is normally 4 bytes in 32-bit machine and 8 bytes in 64-bit machine.


firstname is a char array carrying a trailing 0-terminator. lastname is a pointer. On a 64bit system pointers are 8 byte wide.


The size of your first array is the size of bobby\0. \0 is the terminator character, so it is 6.

The second size is the size of a pointer, which is 8 byte in your 64bit system. Its size doesn't depends on the assigned string's length.

Tags:

C

Char

Sizeof