And if you change your example only slightly, you can break again most-people's mental-model of pointers:
#include <stdio.h>
void fn(char *s) {
printf("[%s]\n", s);
}
int main() {
char *s;
s = "hello world";
fn(s);
return 0;
}
And yet again: #include <stdio.h>
void fn(int s) {
printf("[%s]\n", (char *)s);
}
int main() {
char *s;
s = "hello world";
fn((int)s);
return 0;
}
And back to a single char: #include <stdio.h>
void fn(char *c) {
printf("[%c]\n", *c);
}
int main() {
char c = 'a';
fn(&c);
return 0;
}
The ugly and evil way: #include <stdio.h>
void fn(char *c) {
printf("[%c]\n", c);
}
int main() {
int c = 'a';
fn((char *)c);
return 0;
}
And the obvious way: #include <stdio.h>
void fn(char c) {
printf("[%c]\n", c);
}
int main() {
char c = 'a';
fn(c);
return 0;
}
It is not difficult to see why most people find pointers in C confusing.