+ 1
Memory allocation im C
I am interested im memory allocation in C language. I can't imagine how variable with allocated memory (malloc) behave when has bigger size than allocated bytes. Here is code: int main() { char* str = (char*) malloc(3); strcpy(str, "Long sentence."); printf("%s", str); return 0; }:
8 odpowiedzi
+ 2
Always assume the worst: Your program will probably crash.
+ 1
Now I understand, unpredictable results are unwanted forced changes in memory.
+ 1
Sometimes I get Segmentation Fault but mostly program runs and able to corrupt other variable
If you are getting ERROR then try to re-run it
https://code.sololearn.com/cTiww2y4hfG9/?ref=app
0
Thanks for fast answer, so when allocated memory is too small for value like char array, it is re-allocated?