I am just getting used to pointers in C. I was thinking of using %s to print the first character of a character array.
In the following code, why does %s not work, but %c works? If *my_string is dereferencing the first value of the character array, wouldn't %s try to print all the characters in memory starting at that address and continue until a null-zero character is reached?
Also, how is printf("%s", my_string) working, but printf("%s" *my_string) is not?
char* my_string = "The original value.";
printf("Value of my_string: %s\n", my_string);
my_string = "The new value.";
printf("Value of my_string: %s\n", *my_string); // Error
printf("Value of my_string: %c\n", *my_string); // Prints only the first letter 'T', but does not have any errors
%sexpects a null terminated string,*my_stringis not a pointer, it is acharvalue, and%stries to use that value as a pointer, which is obviously wrong.my_stringis the address,*my_stringis the contents of that address.%sexpects the former, not the latter.