Ticker

6/recent/ticker-posts

C Language (What is pointer in C)

WHAT IS POINTER IN C

Pointer is a special variable and it is used to hold memory address of another variable.
Pointers are also used to dynamic memory allocation (Memory allocate at run time)





POINTER OPERATORS
There are two types of operators in pointer.

1. * (The indirection of operator): This operator is used to declare a pointer variable. 

2. & (The address of operator): This operator is used to assign memory address of another variable by pointer variable. 

POINTER EXAMPLE IN C
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int *p;   // Declare a pointer  variable
int num;  // Declare a simple integer variable 

printf("Enter any integer variable: ");
scanf("%d", &num);

// Assign memory address by *p pointer
p = &num;

printf("\nValue of num variable is: %d",*p);
printf("\nAddress of num variable is: %u, p);

getch();
}

PROGRAM EXPLANATION
In the above program, we declared 'p' as pointer variable and 'num' is a simple integer variable. 

After enter value in the ''num variable we are assigning address of 'num' variable in the pointer variable p.

At last we are printing value with the help of pointer variable p

Note: %u is used to print memory address.















Post a Comment

0 Comments