Why does printing a character with %s gives a segmentation fault everytime?
#include <stdio.h>
int main()
{
char c = 'a';
printf("%s",c);
return 0;
}
if may be it's due to not getting '\0' and it continues to read unless accessing read only memory locations, why does this happens all the time? (as it should get \0 somewhere (most probably) as this code does
#include <stdio.h>
int main()
{
char c[2];
c[0] = 'a';
c[1] = 'a'; //skipping '\0'
printf("%s",c); //aa..(then some random output)
return 0;
}
Sorry If the question was silly, I am just a beginner.