#include <stdio.h>
int main(void){
int a = 6;
int *pa;
pa = &a;
printf("%d\n",*pa); //6
printf("%d\n",pa); //1575619476
printf("%s\n",pa); //nothing, a empty line
char *s="test";
printf("%d\n",s); //183013286
printf("%s\n",s); //test
}
The code is simple, pa is a int typed pointer, we print pa, we get a memory address, we print *pa, we get its value;
But when it comes to a char typed pointer, things get interesting, it seems that printf can pick up the according type that it needs to output,
- it needs a number, the "s" will give its address since it is a pointer;
- it needs a string, the "s" will give the value to it.
OR does it means it is "s"'s responsible to give the proper value to printf? But it is not a object, how does the single value know some self-action?
what happened here?