Wednesday, June 27, 2012

Misc C Conecpts [Uncategorised]

1.What is the memory allocated for the following definition.

char* n[]={"name1","name2","name3"};

Solution:
n is an array of 3 elements. Each element is the address of a const char array. The sizeof n is the size of 3 addresses. On my machine this is 12 bytes.

n is not a two dimesional array. The strings are 6 bytes .So
Memory for 3 pointers[12 bytes] + memory for 3 string literals[18 bytes]=30 bytes

2.