I don't understand why this code provoke no Segmentation Fault :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (void){
char* c;
strncpy(c,"Gustave",10);
return 0;
}
And this one does :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void aux (void){
char* c;
strncpy(c,"Gustave",10);
}
int main (void){
aux();
return 0;
}
For me the two are supposed to make a Segmentation Fault because we are accessing non allocated memory.
Another question would be :
Why does this provoke a Bus Error, not a segmentation Fault :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void aux (void){
char* const c = "Bonjour";
strncpy(c,"BonjourBonjour",20);
}
int main (void){
aux();
return 0;
}