difference between pointer and reference in c?

前端 未结 9 1531
傲寒
傲寒 2020-12-25 08:11

what is the difference between pointer , reference and dereference in c?

9条回答
  •  暖寄归人
    2020-12-25 08:48

    C has pointers and you can pretty much do anything you want with those pointers, you can deference them, and you change the value of a pointer. In fact pointer arithmetic is quite common technique in C programming. In my younger days as a C programmer references was not a commonly used term when talking with other C developers.

    References as a term is very commonly used with Java, C# and Object Oriented Languages. In the context of Java and Object Oriented languages a reference is a pointer to an object instance in memory. With a reference you can't do pointer arithmetic, and that is the key difference between pointers and references in my view.

    Pointers allow for pointer arithmetic and dereferencing, references only allow for dereferencing and changing what the reference points to.

提交回复
热议问题