Strange behaviour when printing pointers

后端 未结 4 1260
执念已碎
执念已碎 2020-12-21 18:08

I have the following code:

#include 

typedef struct {
  int* arg1;
  int  arg2;
} data;

int main(int argc, char** argv) {
  data d;
  printf         


        
4条回答
  •  一整个雨季
    2020-12-21 18:22

    You are accessing uninitialized values. This causes undefined behaviour (meaning that anything can happen, including the program crashing).

    To fix, initialize values before using them, e.g.:

     data d = { 0 };
    

提交回复
热议问题