On Aug 21, 8:53 am, raashid bhatt <raashidbh...@gmail.comwrote:
#include <stdio.h>
int main(int argc, char **argv)
{
char i[][10] = {"welcome", "nelcome"};
// pointer to the array of chars
char (*p)[] = {"Welcoem", "welcome"}; //dosent work
p is a pointer to an array; as such, it is expecting an array address,
not 2-d array initializer.
What you're looking for is something like this:
char (*p)[] = &"Welcome"; // note the presence of the & operator
Alternately, something like this:
char a[] = "Welcome";
char (*p)[] = &a;
// array of pointer to chars
char *s[] = {"welcome", "welcome"}; // works strange!
String literals are stored as arrays of char; if a string literal
appears anywhere other than as an operator to & or sizeof, the usual
array conversions come into play (i.e., the reference to the string is
converted to type char*, and the value of the reference is set to
point to the first character in the string).
So your initializer can be seen as two objects of type char*.
return 0;
}
You really, really, *REALLY* need to get a good C reference manual,
because you've been asking some very basic questions that are best
answered by such a reference. My main reference is Harbison &
Steele's "C: A Reference Manual" (currently 5th edition). Whatever
you get, go there *first*, and if something still doesn't make sense,
feel free to ask here.