Pointers One Powerful Complicated Features C Enable Us Store Memory Address Another Varia Q37227880

Pointers are one of the most powerful and complicated featuresof C++. They enable us to store the memory address of anothervariable, and use this memory address to access and modify thevariable. Consider the following C++ code:

float var = 4.2;float *ptr = &var;*ptr = 1.7;

Rule 1: Whenever we use * in a variabledeclaration between the data type and the variable name, we aredeclaring a pointer variable. In line two above we have declaredptr to be a pointer.

Rule 2: Whenever we use & just before avariable name, we are asking for the address of the variable. Inline two above, ptr is initialized

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.