Sunday, March 5, 2017

Arrays and Pointers in C++

Hi there here is a sample program that shows you how to use one dimensional array and pointers in C++ this code I used it before in my programming class in C++ in college. The code is very short and easy to understand. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Program Listing


#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 "
       << val[0] <<  ","
      << val[1] <<  ","
      << val[2] <<  ","
      << val[3] <<  " is "
      << add(val[0],val[1],val[2],val[3])
      << ".";
      cout << "\n\n";
      system("pause");
}


No comments:

Post a Comment