Hello i am writing a program and i have declared a string in this way:
char *string=malloc(sizeof(char));
In my laptop i am using 64 bit Mint OS and everything is working fine.However in a 32 bit Debian machine i get in that line of code a segmentation fault.If i declare the string without malloc,like this: char string[100] the program is working fine.When i run the program with GDB it says malloc.c not found or something like that.Is this behavior logical?If someone has experienced the same issue before can please explain me why its happening?Thanks in advance.
Adding to the other answer, I try to explain why it fails on 32 bit, but succeeds on 64 bit:
Most probably, your memory manager works with a certain granularity which depends on the word size of your system. Maybe it is 4 bytes on a 32 bit system and 8 bytes on a 64 bit system. (I am not sure if this is correct, however.)
If you allocate 1 byte, there are 3 resp. 7 bytes which are not used. So while you are not allowed to use them, nothing will happen.
If you use more than 3, but up to 7 bytes of them, nothing will happen on a 64 bit system, but on a 32 bit system, the program crashes.