Benefits of pointers?

后端 未结 11 1529
不知归路
不知归路 2021-01-03 23:40

I recently developed an interest in C programming so I got myself a book (K&R) and started studying.

Coming from a University course in Java (basics), pointers a

11条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-04 00:06

    Let me explain this more in terms of Java references (as pointed out by @Greg's answer)

    In Java, there are reference types (i.e. reference to a class) and value types (i.e. int). Like C, Java is pass by value, only. If you pass a primitive type into a function, you actually pass the value of the value (after all, it is a "value type"), and therefore any modifications to that value inside that function are not reflected in the calling code. If you pass a reference type into a function, you can modify the value of that object, because when you pass the reference type, you pass the reference to that reference type by value.

提交回复
热议问题