Directly assigning values to C Pointers

后端 未结 3 646
后悔当初
后悔当初 2020-12-04 10:53

I\'ve just started learning C and I\'ve been running some simple programs using MinGW for Windows to understand how pointers work. I tried the following:

#in         


        
3条回答
  •  遥遥无期
    2020-12-04 11:38

    In the first example, ptr has not been initialized, so it points to an unspecified memory location. When you assign something to this unspecified location, your program blows up.

    In the second example, the address is set when you say ptr = &q, so you're OK.

提交回复
热议问题