What is the reason that the first codeblock doesn’t work whereas the latter one works fine?
#include <stdio.h>
int main(void) {
char grade = 'A';
printf("My friend got an %s grade", grade);
return 0;
}
Segmentation fault
#include <stdio.h>
int main(void) {
char grade[] = "A";
printf("My friend got an %s grade", grade);
return 0;
}
My friend got an A grade
New contributor
Student is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.