Possible Duplicate:
What is the difference between char s[] and char *s in C?
char *p="Help"
printf("%ud",p);
i get the base address of “Help” as output.Does that mean that a string(“Help”)always returns its base address.If so Is this the same case with C++.
also can u explain what exactly is happening below.
char name[]="Hello";
I know this is silly but my brain is not in peace.
In the first example you give in your post you are using a pointer which points to an address in memory where the characters are stored. That’s why when you print p you get an address.
In your second example you are creating an array of characters each storing a letter in “Hello”. An array uses some similar memory access principles in that each character is stored in sequential memory locations so name[] is a memory location and then any index you access is an offset in memory to the first pointer name[] where the first element lives.
Say, for simplicity, that name[0] = 0x00, name[1] = 0x01, name[2] = 0x02 and so on. Now, each of those memory locations holds a value which represents part of your string “Hello”. When accessed, it is known where name[x] is by which index you are accessing and you get that memory location or character depending on how you access the element.