Are pointers considered a method of calling by reference in C?

后端 未结 8 1640
暖寄归人
暖寄归人 2021-01-30 10:31

In my University\'s C programming class, the professor and subsequent book written by her uses the term call or pass by reference when referring to poin

8条回答
  •  南笙
    南笙 (楼主)
    2021-01-30 10:50

    From the C99 standard (emphasis mine):

    6.2.5 Types

    20 Any number of derived types can be constructed from the object and function types, as follows:

    ...

    — A pointer type may be derived from a function type or an object type, called the referenced type. A pointer type describes an object whose value provides a reference to an entity of the referenced type. A pointer type derived from the referenced type T is sometimes called ‘‘pointer to T’’. The construction of a pointer type from a referenced type is called ‘‘pointer type derivation’’. A pointer type is a complete object type.

    Based on the above, what your professor said makes sense and is correct. A pointer is passed by value to functions. If the pointer points to a valid entity, its value provides a reference to an entity.

提交回复
热议问题