When I try to run the following code, I get a seg error. I tried to run it through gdb, and I understand that the error occurs as part of the call printf, but I lost why it doesn’t work.
#include <stdlib.h>
#include <stdio.h>
int main() {
char c[5] = "Test";
char *type = NULL;
type = &c[0];
printf("%s\n", *type);
}
If I replaced printf("%s\n", *type);
with printf("%s\n", c);I get the "Test" as I expected. Why doesn't it work with a pointer to a char array?
source
share