Category Archives: Pointer

Null Pointer in C

In this tutorial you will learn about null pointer in C with examples. When we declare a pointer, by default it points to some random memory location. If you will access the pointer then it may give some undesired value or the program may crash. What is Null Pointer in C? A pointer pointing to… Read More »

Difference between Reference and Pointer in C++

Here you will learn about difference between reference and pointer in C++. Reference: Reference contains address of a variable. It can be called as alternative name of a variable. Example:

Pointer: Pointer also contains address of a variable. Example:

Both reference and pointer are used to point to address of a variable but they are different… Read More »

Pointer to Pointer or Double Pointer in C

In this tutorial you will learn about pointer to pointer or double pointer in C. Pointer is used to store memory address of variable. Double pointer is used to store memory address of any other pointer. Let’s try to understand this by one example. Also Read: void pointer in C Also Read: C Function Pointer   Pointer… Read More »

C++ Program to Compare Two Strings Using Pointers

In below program we are comparing two string with the help of pointers, without using strcmp() function. A user defined function str_cmp() is created which takes two character pointers as argument. If this function returns 1 than the strings are equal and unequal if returns 0. Just take a look on the program, if you… Read More »

C++ program to swap two numbers using pointers

#include<iostream.h> #include<conio.h> void main() { clrscr(); int *a,*b,*temp; cout<<“Enter value of a and b:”; cin>>*a>>*b; temp=a; a=b; b=temp; cout<<“nAfter swapingna=”<<*a<<“nb=”<<*b; getch(); }

C program to swap two numbers using pointers

#include<stdio.h> #include<conio.h> void main() { int *a,*b,*temp; clrscr(); printf(“Enter two mumbers:”); scanf(“%d%d”,a,b); printf(“Before Swaping:na=%d b=%d”,*a,*b); temp=a; a=b; b=temp; printf(“nAfter Swaping:na=%d b=%d”,*a,*b); getch(); }

C program to read and display an array using pointer

#include<stdio.h> #include<conio.h> void main() { int a[50],*p,i,n; clrscr(); p=a; printf(“Enter size of array:”); scanf(“%d”,&n); printf(“Enter elements of array:”); for(i=0;i<n;++i) scanf(“%d”,p+i); for(i=0;i<n;++i) printf(“%d “,*(p+i)); getch(); }