|
|
|
dataType *varName ; |
Meaning:
|
int *p ; // p can contain the address of an int typed variable float *q ; // q can contain the address of a float typed variable |
(I will explain the notation in a later webpage)
|
int a; // an int typed variable // So: a can store an integer value int *p; // p can hold an address of an int typed variable // So: p can store an address of an integer variable p = &a; // Store the address of the int type variable a in p |
What happens inside the computer:
|
|
|
int main(int argc, char *argv[]) { int i1 = 4, i2 = 88; int *p; printf("Address of i1 = %u\n", &i1 ); // %u = unsigned integer printf("Address of i2 = %u\n\n", &i2 ); p = &i1; // p points to variable i1 printf("Value of p = %u\n", p ); printf("Value of *p = %d\n\n", *p ); p = &i2; // p points to variable i1 printf("Value of p = %u\n", p ); printf("Value of *p = %d\n\n", *p ); } |
Output:
Address of i1 = 4290768712 Address of i2 = 4290768708 Value of p = 4290768712 Value of *p = 4 Value of p = 4290768708 Value of *p = 88 |
How to run the program:
|
|
|
int main(int argc, char *argv[]) { int i1 = 4, i2 = 88; int *p; printf("Value of i1 = %d\n", i1 ); p = &i1; // p points to variable i1 *p = 1234; // Store 1234 in i1 !!! printf("Value of i1 = %d\n", i1 ); printf("Value of i2 = %d\n", i2 ); p = &i2; // p points to variable i2 *p = 9999; // Store 9999 in i2 !!! printf("Value of i2 = %d\n", i2 ); } |
Output:
Value of i1 = 4 Value of i1 = 1234 (i1 is changed !!!) Value of i2 = 88 Value of i2 = 9999 (i2 is changed !!!) |
How to run the program:
|
|
Then:
C expression Similar to M68000 --------------------------------------------------- p A0 *p (A0) Examples: p = &var; move.l #var, A0 *p = 1234; move.l #1234, (A0) |
|
|