阅读背景:

在C ++中声明一个指向struct的指针会自动为其成员分配内存。我错了吗?

来源:互联网 

I wrote the following piece of code and I believed it would crash if I tried to access the members of a struct for which I didn't even allocate memory. But I was quite suprised that C++ automatically allocated memory for the struct. Is that normal behavior? For comparison, if you declare a pointer to an object and then try to access any members without actually creating the object with the operator "new", the program would crash. I'm just curious about why it works when I believe it shouldn't.I wrote the following piece of code and I belie




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: