by Dinesh Thakur Category: Function and Pointer

To manipulate data using pointers, the C language provides two operators: address (&) and dereference (*). These are unary prefix operators. Their precedence is the same as other unary operators which is higher than multiplicative operators.

The address operator (&) can be used with an lvalue, such as a variable, as in &var. This expression yields the address of variable var, i.e., a pointer to it. Note that the address operator cannot be used with constants and non-lvalue expressions. Thus, the expressions &100,&(a+5) and &'X' are invalid. If the type of variable var is T, the expression &var returns a value of type T *,i.e., a pointer to type T. As mentioned earlier, we need not know the exact address where a particular variable is stored in memory. We can use the addressoperator to obtain its address, whatever it may be. This address can be assigned to a pointervariable of appropriate type so that the pointer points to that variable.

The dereference operator (*) is a unary prefix operator that can be used with any pointer variable, as in *ptr_var. This expression yields the value of the variable pointed at by that pointer. Although the symbol for the dereference operator is the same as that of the multiplication operator, its use is unambiguous from the context as the latter is a binary infix operator used, as in expr1 * expr2.



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles