Home > Backend Development > C++ > C or C Pointer Declaration: Where Should the Asterisk Go?

C or C Pointer Declaration: Where Should the Asterisk Go?

DDD
Release: 2024-12-17 17:01:19
Original
881 people have browsed it

C or C   Pointer Declaration: Where Should the Asterisk Go?

Pointer Declaration: Asterisk Placement Quandary

In the realm of C and C programming, the placement of the asterisk in pointer declarations has sparked a heated debate. The two prevalent methods are juxtaposing the asterisk with either the type name or the variable name.

C Style: Emphasizing Pointer Type

Advocates of this style prioritize the pointer's type. This declaration denotes that somePtr is a pointer of type someType.

C Style: Emphasizing Pointed-to Type

In this approach, the asterisk's adjacency to the variable name highlights the data type pointed to by somePtr.

Preference and Semantics

Ultimately, the choice between these two styles is a matter of personal preference. There is no definitive consensus on which one is superior.

However, some proponents argue that the C style aligns better with the object-oriented paradigm, as it emphasizes the pointer's type. On the other hand, the C style may be more intuitive for programmers accustomed to its notation in C.

Middling Placement: Avoiding Commitment

A third approach, placing the asterisk in the middle (e.g., someType *somePtr), attempts to avoid adhering to either the C or C style. However, this middle ground does not offer any additional semantic benefit.

The above is the detailed content of C or C Pointer Declaration: Where Should the Asterisk Go?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template