Pointer: A variable that contains the address of a variable.
http://siber.cankaya.edu.tr/OperatingSystems/cfiles/code6.c code6.c
#include <stdio.h>
int main(int argc, char *argv[])
{
int x = 1, y = 2, z[10];
int *ip; /* ip is a pointer to int */
ip = &x; /* ip now points to x */
printf("The address of pointer 'ip' is %p \n",&ip);
printf("The thing that pointer 'ip' contains inside is %p \n",ip);
printf("The thing that pointer 'ip' points is %d \n",*ip);
printf("The address of variable 'x' is %p \n",&x);
printf("The value of variable 'x' is %d \n",x);
y = *ip; /* y has the value of x now */
*ip = 0; /* x is 0 now */
ip = &z[0]; /* ip now points to z[0] */
return 0;
}
- Analyze the code.
- Execute the code. What is the output and why?
- Exercise: Modify the code above that ;
- creates two 'double' type pointers,
- puts numbers in,
- prints out the values inside the pointers (address info.),
- prints out the values that pointers point.