I'm not quite sure I get how malloc
works exactly.
#include <stdio.h>
#include <stdlib.h>
int main() {
char * string = (char*) malloc(sizeof(char));
string = "abc";
int * test = (int*) malloc(1 * sizeof(int));
*(test) = 5;
*(test + 1) = 6;
}
I expected this to output an error since the value I appoint to string is bigger than just one char yet it seems to compile just fine.
I have a few questions:
Where would 'string' be saved now? is it on memory spaces on the heap after the one space I allocated ?
Why is does the char let me appoint directly and the int only via pointer?
I'm really not sure what I'm doing here