Professional Documents
Culture Documents
❖ BASICS OF POINTERS
❖ P O I N T E R A N D A R R AY
❖ POINTER AND STRING
❖ A R R AY O F P O I N T E R S
❖ POINTER AS A FUNCTION ARGUMENT
VAR_NAME
Syntax:
VALUE/
Datatype *ptr_var_name; DATA
Example: ADDRESS OF
VARIABLE
int *pnum;
char *pch;
float *pfnum;
Var_name *p num
Value /
Data -12 10
Address of
variable
-14 -12
PROF. BHARGAVI S RANI CHAPTER 6 5
Swap 2 numbers using pointers
2. Void pointer: It is a pointer that has no associated data type with it. A void pointer can
hold addresses of any type and can be typecast to any type.
It is also called a generic pointer and does not have any standard data type.
void *p = NULL; //void pointer
3. Null pointer: create a null pointer by assigning the null value at the time of pointer
declaration.
[ Null is a built-in constant that has a value of zero ]
int *ptr = NULL; //null pointer
The following
declaration:
declares a pointer to a
pointer of type int −
int **var;
X[4]
1 2 3 4 5
Output
* ptr = 3
*(ptr+1) = 4
*(ptr-1) = 2
OUTPUT
arrop[0] = &a;
Expected Output:
arrop[1] = &b;
arrop[2] = &c; Address = 387130656 Value = 10
Address = 387130660 Value = 20
Address = 387130664 Value = 50
for(i = 0; i < 3; i++)
{
printf("Address = %d\t Value = %d\n", arrop[i], *arrop[i]);
}