#include<stdio.h>

int main(int argc, char *argv[])
{
    char *states[] = {
        "California", "Oregon",
        "Washington", "Texas"
    };

    printf("size of states: %d",sizeof(states));

    return 0;
}

the result of this is:
size of states: 16

why is that?I know that an int is 4 bytes,while a char is 1 byte.I got confused why it's 16 and not 4.

sizeof(states) gives you the number of bytes in the array. The number of bytes in an array equals the number of elements times the number of bytes per element. The elements in states are char pointers and apparently pointers have 4 bytes on your platform (so you're running a 32-bit system or at least a 32-bit compiler), so we get 4 * 4 = 16 bytes total.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.