私はCを学んでおり、これを行いました(以下のコードで、0であるはずの-1073740940のようなプログラムの戻り値を取得する理由がわかりません
#include <stdio.h>
#include <stdlib.h> //For using malloc;
struct Vertex{
int x;
int y;
int z;
};
int main(){
int ret = 0;
struct Vertex myVertex;
struct Vertex *myVertexPtr = malloc(sizeof(*myVertexPtr));
myVertexPtr = &myVertex;
myVertex.x = 1;
myVertex.y = 2;
myVertex.z = 3;
printf("%d\n", myVertexPtr->x);
printf("%d\n", myVertexPtr->y);
printf("%d\n", myVertexPtr->z);
getchar();
free(myVertexPtr); //When this line is included I get the strange program return value (And, "This program has stopped working properly windows error")
//When this line is not included it returns fine, but I'm under the impression it is good practice to free pointers
return 0;
}
MinGW GCC を使用してコンパイルしています