C++ Program to Access Elements of an Array Using Pointer

Hi,Hope you are Fine and Today we make Discuss how to use one dimensional array and pointers in C++.you can edit Things in this code.and use it with some new changing.

C++ Program to Access Elements of an Array Using Pointer

Source Code

#include <iostream>
using namespace std;
int add(int &a,int &b, int &c, int &d)
{
return(a+b+c+d);
}

main() {
int val[4];
val[0] = 2;
val[1] = 4;
val[2] = 6;
val[3] = 8;

cout << "The sum of \n"
<< val[0] << "\n"
<< val[1] << "\n"
<< val[2] << "\n"
<< val[3] << " \nis "
<< add(val[0],val[1],val[2],val[3])
<< ".";
cout << "\n\n";
system("pause");
}

Output of Code

Enter elements: 1
2
3
5
4
You entered: 1
2
3
5
4