In the following two pieces of code, I don't get why the latter one gives a segmentation fault. I apparently wrongly assume that I'm passing an address in both cases... A pointer is an address right?
So this one works:
#include<iostream>
using namespace std;
int test(char *a) {
*a = *a + 15;
return 0;
}
int main() {
char b;
b = 'c';
cout << b;
test(&b);
cout << b;
}
It outputs:
r
But this one gives segmentation fault, why?:
...
int test(char *a) {
*a = *a + 15;
return 0;
}
int main() {
char *b;
*b = 'c';
cout << b;
test(b);
cout << *b;
}