Home > Article > Backend Development > How Many Levels of Pointers Can You Have in C?
Maximum Number of Pointers in a Variable
In C programming, a pointer points to the memory location of another variable. In theory, we can have an infinite number of pointers pointing to each other. However, in practice, the number of levels of pointers that can be used is limited by the compiler and the underlying hardware.
Implementation-Specific Limits
The C standard only specifies a lower limit of 12 levels of pointers. This means that every compiler implementation must support at least 12 levels. However, the upper limit is not defined in the standard and is therefore implementation-specific.
Example with 12 Pointers
The following code snippet shows an example with 12 levels of pointers:
<code class="C">int a = 10; int *p1 = &a; int **p2 = &p1; // ... int ****************p12 = &p11;</code>
Considerations
While it is technically possible to have many levels of pointers, it is important to consider the following:
In general, it is recommended to use the minimum number of pointers necessary for your program. Overuse of pointers can lead to performance and maintenance issues.
The above is the detailed content of How Many Levels of Pointers Can You Have in C?. For more information, please follow other related articles on the PHP Chinese website!