& and * are both known as pointer operators. Let’s see the use of pointer operators with a variable, a constant, or an expression.

& with a variable, a constant, and an expression

& is called the address-of operator. & can only be used with a variable, as a variable is allocated space in memory. Whereas, the compiler does not reserve any space for a constant or an expression.

📝 Note: Constants go in registers and are used from there. In that sense, they do not get space in memory as variables do.

Example program 1: using & with a variable

The program given below will compile successfully, as we can use & with the variable.

Get hands-on with 1200+ tech skills courses.