char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
how can &alphabet = alphabet ?
that means "alphabet" contains it's own address.
so how can alphabet[0] = 'a' ?
this is my understanding of the following. correct me if i am wrong:
Thanks
char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
how can &alphabet = alphabet ?
that means "alphabet" contains it's own address.
so how can alphabet[0] = 'a' ?
this is my understanding of the following. correct me if i am wrong:
Thanks
When the name of an array is used in an expression there is a conversion to a pointer to the first element of the array.
It's just the way the language was defined. The name of the array alone is defined (to the compiler) as the address of the first element. So, you can't have an array called alphabet[], and another (different) variable called alphabet.how can &alphabet = alphabet ?
Both &alphabet and alphabet point to the address of the 'a' in your string array.
I'd say this was done to make it easy to pass an array to a function, but I don't think the designers of C/C++ were trying to make anything easy!
wrong,
&alphabet is not alphabet !!
alphabet is a pointer to the first character while &alphabet is a pointer to the variable alphabet.
alphabet is a char *
&alphabet is a char **
To be exact, &alphabet should be of type char (*)[24]. It cannot be of type char ** as if it were, that would mean *alphabet would give access to a variable containing a char pointer, which is not true because alphabet "is" (not really but...) the adress of the first character thus making it a rvalue.