Thursday 14 March 2013

sizeof(char pointer)


main()
{
    char *p;
    printf("%d %d ",sizeof(*p),sizeof(p));
}

Answer:
            1 2
Explanation:
The sizeof() operator gives the number of bytes taken by its operand. ‘*p’ is a character pointer, which needs one byte for storing its value (a character). Hence sizeof(*p) gives a value of 1. Since ‘p’ needs two bytes to store the address of the character pointer sizeof(p) gives 2.


Blog Author: Vijay Kumar

Go to: Java Aptitude

No comments:

Post a Comment