Pointer
Generally a pointer is one which points to something.In program, it means which points the memory address of a variable.
Syntax:
data-type *pointer-name = &variable-name;
Example:
int a; int *p; p=&a;
Here p is int type pointer that means it can point a memory address of int type variable. Data type of pointer and pointing variable must be matched. An int type can’t point a variable of float type.
float a; int *p; p=&a;
is invalid
A pointer points to a memory address – evidence by code
We can see the memory address created for a variable can be shown by “%u” format specifier.
Code Example:
#include<stdio.h> int main() { int a; int *p; p=&a; printf("Address of a = %u\n",&a); printf("Address of a = %u\n",p); }
output
Address of a = 3457867020
Address of a = 3457867020
Next Previous