Array Example in C++

Array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier. Like a regular variable, an array must be declared before it is used. A typical declaration for an array in C++ is:

type name [elements];
then try this example below :
#include <iostream.h>
#include <conio.h>

/*fungsi utama*/
void main(){
//    sayHi();
  int y[] = {1,2,7,4,5};
  int n,r = 0;

  for (n=0;n<5;n++){
      r+=y[n];
   }
   cout<< " " << r;
   getch();
   }
Have a nice try, dude!
 
Previous
Next Post »