How to explain C pointers (declaration vs. unary operators) to a beginner?

前端 未结 23 867
渐次进展
渐次进展 2020-11-30 18:08

I have had the recent pleasure to explain pointers to a C programming beginner and stumbled upon the following difficulty. It might not seem like an issue at all if you alre

23条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 18:34

    The type of the expression *bar is int; thus, the type of the variable (and expression) bar is int *. Since the variable has pointer type, its initializer must also have pointer type.

    There is an inconsistency between pointer variable initialization and assignment; that's just something that has to be learned the hard way.

提交回复
热议问题