Uninitialized pointers in code

后端 未结 8 2270
旧巷少年郎
旧巷少年郎 2020-11-30 03:15

I am learning C++ and I came to know that pointers if left uninitialized could point to random locations in memory and create problems that memory might be used by some othe

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 03:36

    If the pointer is not used, the compiler will simply ignore it. Initializing it to NULL is the safe thing to do, imho.

    Are you sure your not confusing with a function declaration? It's very common for a function to be declared as

    char* do_something(const char* one,const char* two);

    In this case, the pointers are used to specify what kind of argument you want to pass.

提交回复
热议问题