Professional Documents
Culture Documents
This creates a string for the literal (i.e. allocates memory and
stores the word good) and then stores its address in the
pointer variable str.
In C constant character strings represents pointer to
themselves.
For e.g. Delhi is a pointer to itself.
So we can use the following
char * string1;
string1 = good;
The second statement is not a string copy operation but
since the constant word good is a pointer to itself so the
pointer string 1 is given the address of good.
To print the string just use:
printf (%s, string1);
Array of Pointers
E.g.
char name[3][25];
char *name[3] = {New Zealand,
Australia, India};
Over here a pointer array is declared in which 3 pointers can
be stored.
So as we already know that the constant strings are pointers
to themselves, so the above assignment is same as
name[0] = New Zealand;
name[1] = Australia;
name[2] = India;
Here the memory allocated is the sum of the 3 strings not
the 3*25, because the computer already know the size of the
strings you are storing so it allocates only that much
memory.
3. Array of Pointers
https://www.youtube.com/watch?
v=sHcnvZA2u88&index=10&list=PL2_aWCzGMAwLZp6LMUKI3cc7
pgGsasm2_