Review on operators:
|
Example:
The integer addition operator +: (1) + operates on 2 int operands (binary operator) (2) + returns the sum of its operands (3) + returns a result of the type int 3 + 4 = 7 (result) |
The reference operator &:
|
Example:
int a; float b; &a returns the address of the variable a The data type of the result is reference to an int typed variable &b returns the address of the variable b The data type of the result is reference to an float typed variable |
Note: the data type of &a and &b are different !!!
|
In C, the programmer can use the & operator to find the address of any variable in the program:
#include <stdio.h> int i = 4; short s = 5; float f = 6.0; double d = 7.0; int main(int argc, char *argv[]) { printf("Address of i = %p\n", &i ); // %p = pointer printf("Address of s = %p\n", &s ); // The address value printf("Address of f = %p\n", &f ); // is printed in hex printf("Address of d = %p\n", &d ); } |
This feature is not available in any other programming language (except C++)
DEMO: demo/C/set2/ref-op1.c