In: Computer Science
When you create a C string (an array of chars) without the * symbol for pointer, is the pointer towards the 1st char created or not along with the array?
The answer is yes, when we create a C string without * symbol, then also pointer towards the 1st char is created.
We can ellaborate this using various examples:-
Example 1:
// taking a C string
char string[10] = "string";
// if we try to print the 1st character like
printf("%c",string[0]);
// the output will be as
s
Example 2:
// taking a C string
char string[10] = "string";
// print address of 1st char
printf("%d",string);
// output
It will give an address like (-1627204058)
// explanation
Even though we have not created the string using * symbol, the name of the array(here string) holds the base address i.e. the address of the 1st charcter of the string same as a pointer which holds the base address of the array, that's why when we tried to print string[0] we got the 1st character i.e. 's' and when we tried to get address of 1st char, we got it using the name of the array i.e. 'string'. Thus it justifies that a pointer towards the 1st character of the string is always created.