Tuesday, 21 February 2012

What is the value of sizeof(a) /sizeof(char *) in a code snippet: char *a[4]={"sridhar","raghava","shashi","srikanth"};

Explanation:
Here a[4] is an array which holds the address of strings. Strings are character arrays themselves.
Memory required to store an address is 4 bits. So memory required to store 4 addresses is equal to 4*4=16 bits.
char *; is a pointer variable which stores the address of a char variable.
So sizeof(char *) is 4 bits. Therefore sizeof(a) /sizeof(char *) = 16/4 = 4 bytes.