raashid bhatt wrote:
>You might ask what the difference is between p and &p. Both are the
address of the start of the array. But p has type pointer-to-char,
and &p has type pointer-to-array-of-100-chars.
you are wrong p and &p arent the same p points to the address where
the value is stored is "welcome" , and &p contains the address of
pointer itself
You're being confused, I think, by the fact that in most circumstances
an expression that has an array type is implicitly converted to a
pointer to the first element of the array. For instance:
char *q = p;
Since 'p' gets converted into a 'char*' in the above context, it might
therefore seem as though the type of &p should be char**. This would
imply that the implementation has to create an unnamed pointer to that
array somewhere in user memory, and the give you a pointer to that
pointer. However, being the right operand of '&' is one of the three
contexts where an expression of array type does not get implicitly
converted to a pointer to the first element of the array (see
6.3.2.1p3). In this context, p refers to the entire array, and applying
the '&' operator to p gives you a pointer to the entire array, not a
pointer to a pointer. 6.5.3.2p3 says 'If the operand has type "_type_",
the result has type "pointer to _type".' Since the type of 'p' is
"char[100]", the type of &p is "char(*)[100]", not char**.