Okay so thats good that you know that we need to specify the address when assigning something to a pointer as in
char *pt = test;
But as i mentioned before that strings are special in C. They are treated as an array of characters. So when i say
char *test = "hi all";
what this implies is that the address of the first array element(just consider this for the sake of understanding) which is 'h' in this case is assigned to test. So this is how strings are treated in c.
If you were to do the following on the test
printf("\n %c", test); // this would give you 'h'
so now you see that test is having the address of the first element of the array "hi test". Hope this makes it a bit clearer. So in this case test which is a pointer to a char is pointing to the first character 'h' and you can iterate through the array till you hit the terminating character '\0'.
[insert]
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *str = "Hello Sir";
int *p;
int test[] = {1,2,3};
p = test;
printf("\n %c", *str);
while(*str != '\0')
{
printf("\n %c", *str);
++str;
}
getch();
return 0;
}