I m new to programming, there is some part that made me confuse when learning pointer.
code1:
int main()
{
char string[]="hello";
char *my_pointer=string;
printf("first character is %c", *my_pointer);
return 0;
}
output : first character is h
code 2:
int main()
{
char array_of_words[]="one\0two\0three";
char *my_pointer=array_of_words;
printf("%s \n",my_pointer);
return 0;
}
output : one
questions:
I'm confuse here, the printf function part in the first code using asterisk symbol means to point what is inside pointer (my_pointer) which is the address of variable string that refer to the pointer string for an array that point the memory address of the first word in array "hello". is my understanding true?
and also when I change %c in printf("first character is %c", *my_pointer); to %s, the program crash. i want to know why i cant use %s and what is the different if i dont use asterisk in my_pointer in printf("first character is %c", my_pointer);
While in second code my_pointer variable didnt use asterisk(*) in {printf("%s \n",my_pointer);}. in this code is my_pointer refer to the address of array_of_words variable or what is inside of my_pointer? and also why the output is 'one' not 'o'?