Introduction
Control Statement
- Program to identify day of week
- Program to print Fibonacci series
- Check Whether the Number is Even or Odd in C++
- Program to check whether the number is prime or not
- Program to check vowel or constant
- Program to check the largest number among three numbers
- Program to the sum of natural numbers
- Program to check leap year
- Program to find factorial of the number
Function
- Program to find LCM
- Program to check prime number using Functions
- Program to convert Binary to Decimal Number
- Program to convert Decimal to Binary Number
- Program to convert Binary to Octal Number
- Program to convert Octal to Binary Number
- Program to find reverse of the sentence using Recursion
- Program to Shutdown and restart Computer
- Program to find the area of triangle
Array
Pointer
OOPS
No Examples found for this topic - CodeHelpPro
Program to Traverse array using pointer
In this program, we will learn to traverse array using pointer. It is simple pointer example. If you are beginner in pointer then check the pointer tutorials before learning this example
In this example, data are stored in variable data[].
Then we will access the elements using pointer notation. On thing you must know in pointer
- arr[0] is equal to *arr and &arr[0] is equal to arr
- arr[1] is equal to (*arr + 1) and &arr[1] is equal to arr + 1
- ….
- arr[i] is equal to (*arr + i) and &arr[i] is equal to arr + i
To know more about relationship, Check tutorial [Relationship between Array and Pointer]
Example: Traverse array using pointer
#include <iostream>
using namespace std;
int main()
{
int *ip;
int arr[] = {1, 2, 3, 4, 5, 6};
ip = arr;
for (int x = 0; x < 6; x++)
{
cout << *ip << endl;
ip++;
}
return 0;
}
The output of above program is
Subscribe
Login
0 Comments
Inline Feedbacks
View all comments