Clouds
Home
Tutorial of C language
Computer Language
Introduction to C
Programming in C
Structure of C program
Variable in C
Datatypes in C
Token in C
Operator in C
Precedence of C Operator
Assignment Operator in C
Logical Operator in C
Bitwise Operator in C
Ternary Operator in C
C Input Output
Pointers in C
Storage Classes of C
Control Structure of C
C Decision Making Statement
C Looping Statement
C Jumping Statement
C Function
Function Call By Value
Function Call By Reference
C Input Output Function
C Structure
Array in C
Union in C

Pointer

  • A Pointer is simply a variable that can hold the address of another variable
  • A pointer is a special kind of variable. Pointers are designed for storing memory address i.e. the address of another variable.
  • Declaring a pointer is the same as declaring a normal variable except you stick an asterisk '*' in front of the variables identifier.

    Syntax:-

    datatype Pointer-variable;

    Example:-

    				int a, *p;
    				
  • a - is a simple variable
  • *p - is a pointer variable. Two operators are use in pointer to access the variable
  • Indirection Operators (*)
  • Address Operator (&)

    Indirection Operators (*):-

    Indirection operators is use to get the value at address

    Address Operator (&):-

    Address operator is use to get the address of a variable.

    Example1:-

    				#include<stdio.h>
    				#include<conio.h>
    				void main()
    				{
    					int a=5;
    					clrscr();
    					printf("%d",a);
    					printf("%u",&a);
    					getch();
    				}
    				

    Example2:-

    				#include<stdio.h>
    				#include<conio.h>
    				void main()
    				{
    					int a=5,*p;
    					p=&a;
    					printf("%d",a);
    					printf("%u",&a);
    					printf("%d",p);
    					printf("%u",&p);
    					printf("%d",*p);
    					getch();
    				}
    				

    Example3:-

    				#include<stdio.h>
    				#include<conio.h>
    				void main()
    				{
    					int a=5,*p1,**p2;
    					p1=&a;
    					p2=&p1;
    					printf("%d\n",a);
    					printf("%u\n",&a);
    					printf("%d\n",p1);
    					printf("%u\n",&p1);
    					printf("%d\n",*p1);
    					printf("%d\n",p2);
    					printf("%u\n",&p2);
    					printf("%d\n",*p2);
    					printf("%d\n",**p2);
    					getch();
    				}
    				

    Question:- WAP Enter two no. then print the sum of two no. using pointer.

    				#include<stdio.h>
    				#include<conio.h>
    				void main()
    				{
    				 	int a,b,sum,*pa,*pb,*psum;
    				 	printf("Enter the value of a & b: ");
    				 	scanf("%d%d",&a,&b);
    				 	pa=&a;
    				 	pb=&b;
    				 	psum=∑
    				 	*psum=*pa+*pb;
    				 	printf("%d",*psum);
    					getch();
    				}
    				

    Question:- WAP Enter two no. then print the highest value using pointer.

    				#include<stdio.h>
    				#include<conio.h>
    				void main()
    				{
    				 	int a,b,*pa,*pb;
    				 	printf("Enter the value of a & b: ");
    				 	scanf("%d%d",&a,&b);
    				 	pa=&a;
    				 	pb=&b;
    				 	if(*pa>*pb)
    				 		printf("Highest value=%d",*pa);
    				 	else
    				 		printf("Highest value=%d",*pb);
    					getch();
    				}
    				

    Storage Classes of C >>
    Control Structure of C >>
    C Decision Making Statement >>
    C Looping Statement >>
    C Jumping Statement >>


    Home Clouds