我正在学习 C 并且我这样做了(下面的代码,我不明白为什么我得到的程序返回值类似于 -1073740940 而它应该是 0
#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 编译