Interview Questions

In C, explain the difference between the & operator and the * operator.

Electrical Engineering Technical Interview Questions and Answers


(Continued from previous question...)

12. In C, explain the difference between the & operator and the * operator.

& is the address operator, and it creates pointer values.
* is the indirection operator, and it dereferences pointers to access the object pointed to.

Example:
In the following example, the pointer ip is assigned the address of variable i (&i). After that assignment, the expression *ip refers to the same object denoted by i:

int i, j, *ip;
ip = &i;
i = 22;
j = *ip; /* j now has the value 22 */
*ip = 17; /* i now has the value 17 */

(Continued on next question...)

Other Interview Questions