Simple Program for Pointer and Array Example in C++
Overview
- Array Pointer Assignment : pointer_variable = &var[position];
- pointer_variable++ is increasing Address value based on Data Type
- pt++; --> Its locate next position of Array
for example,
Array Pointer Assignment
pt = &var[0];
pt++;
now pt++ points var[1] of address.
Syntax
Array Pointer Assignment
pointer_variable = &var[position];
pointer_variable++ is increasing Address value based on Data Type
pt++; --> Its location next position of Array
Simple Program for Pointer and Array Example
/* Simple Program for Pointer and Array Example in C++*/
/* Pointer and Array C++ Program,C++ Pointer Examples */
// Header Files
#include <iostream>
#include<conio.h>
using namespace std;
#define MAX_SIZE 5
int main() {
// Declare Variables
int var[] = {10, 20, 30, 40, 50};
int i = 0;
//Pointer Variable Declaration for Integer Data Type
int *pt;
cout << "Pointer Example C++ Program : Pointer and Array \n";
//& takes the address of var , Here now pt == &var, so *pt == var
pt = &var[0];
while (i < MAX_SIZE) {
cout << "Position : " << i << " # Actual : Value : " << var[i] << " , Address = " << &var[i] << " \n";
cout << "Position : " << i << " # Pointer : Value : " << *pt << " , Address = " << pt << " \n\n";
i++;
// pt++ is increasing Address value based on Data Type
pt++;
}
getch();
return 0;
}
Sample Output
Pointer Example C++ Program : Pointer and Array
Position : 0 # Actual : Value : 10 , Address = 0x6ffe10
Position : 0 # Pointer : Value : 10 , Address = 0x6ffe10
Position : 1 # Actual : Value : 20 , Address = 0x6ffe14
Position : 1 # Pointer : Value : 20 , Address = 0x6ffe14
Position : 2 # Actual : Value : 30 , Address = 0x6ffe18
Position : 2 # Pointer : Value : 30 , Address = 0x6ffe18
Position : 3 # Actual : Value : 40 , Address = 0x6ffe1c
Position : 3 # Pointer : Value : 40 , Address = 0x6ffe1c
Position : 4 # Actual : Value : 50 , Address = 0x6ffe20
Position : 4 # Pointer : Value : 50 , Address = 0x6ffe20
C++ Pointer Example Programs
- Simple Pointer Example Program In C++
- Simple Program for Print address of Variable Using Pointer in C++
- Pointer Simple Example Program with Reference operator (&) and Dereference operator (*)
- Simple Example Program for Swap Numbers Using Pointers In C++
- Print size of different types Using Pointer in C++
- Simple Program for Add Two Numbers Using Pointer in C++
- Simple Program for Increment and Decrement Integer Using Pointer in C++
- Simple Program for Increment and Decrement Floating Point Using Pointer in C++
- Simple Program for Find a difference between two Numbers Using Pointer in C++
- Simple Program for Print String Using Pointer in C++
- Simple Program for Count vowels String Using Pointer in C++
- Simple Program for Length of String Using Pointer In C++
- Pointer to Pointer or Double Pointer Example Program In C++
- Simple Program for Pointer and Array Example in C++
- Simple Program for Sum of Integer an array using pointers in C++
- Simple Program for Read, Print and Sum of Integer in an array using pointers in C++
- Simple Example Program for Passing pointers to functions In C++
- Simple Example Program for Area Of Circle Using Pointer In C++
Read More Articles
- Simple Merge Sort Program in C++
- Scope Resolution Operator In C++
- Simple Program for Virtual Functions Using C++ Programming
- Simple Class Example Program For Find Prime Number In C++
- Simple Example Program For Parameterized Constructor In C++
- Define Constructor in Outside Class Example Program In C++
- Simple Example Program For Copy Constructor In C++
- Simple Program for Function Overloading Using C++ Programming
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Simple Example Program For Constructor Overloading In C++
- Factorial Using Function Example Program In C++
- Simple Example Program for Inline Function Using C++ Programming
- Simple Addition ( Add Two Integers ) Example Program
- Simple Example Program For Constructor In C++
- Simple Program for Read user Input Using cin
- Factorial Using Loop Example Program In C++
- Simple Stack Program in C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Simple Program for Unary Operator Overloading Using C++ Programming
- Simple Program for Multiple Inheritance Using C++ Programming
- Do While Loop Example Program In C++
- Simple Copy Constructor Example Program For Find Factorial In C++
- Simple Program for Virtual Base Class Using C++ Programming