Pointer in c

What is pointer?
Pointer is a variable that point to the address of  variable.

& Operator use to determine the address of another variable.

The asterisk *used to declare a pointer.

Pointer syntax:data_type *var_name;

Example:int *p// p will hold the address of                                   int variable 
                Float *j // j will hold the address of                                     float variable
               Char *q// q will hold the address of                                   char variable

In above example is a pointer variable not a normal variable.

Explanation:


In above example pointer p point to the integer num,in which the integer number contain value 5. So the value of num =5,the value of p is address of num which is 2293596.

Program of pointer

#include<stdio.h>
#include<conio.h>
void main()//main function 
{
  int i=10;
  int *p; //point to the integer variable
  Printf("address of i is %d",&i);
Printf("value of i is %d",i);
  Printf("address of p is %d",p);
  Printf("value of p is %d",*p);
  getch();
}

Output 

address of i is 65500
Value of i is 10
address of p is 65500
Value of p is 10


No comments:

Post a Comment

Loop in c

Types of loop . 1) for loop 2)while loop 3)do-while loop. 1)for loop . For loop is used to repeat the block of code. Syntax of for ...