Display Marks using Array in C++


This is a C++ program that declares an integer array of size 5 called marks and initializes it with some values. It then calls a function called display and passes the marks array as an argument.

The display function takes an array of integers as its argument and prints the marks of 5 students, along with their student number (starting from 1).

Note that the function display takes the array as an argument using the syntax int m[5], which is equivalent to int *m. This means that the function receives a pointer to the first element of the array, and it can access the other elements using pointer arithmetic.

Source Code

#include <iostream>
using namespace std;
void display(int m[5])
{
  cout<<"Displaying marks: "<<endl;
  for (int i=0;i<5;++i)
  {
    cout<<"Student "<<i+1<<": "<<m[i]<<endl;
  }
}
int main()
{
  int marks[5] = {88,76,90,61,69};
  display(marks);
  return 0;
}
To download raw file Click Here

Output

Displaying marks: 
Student 1: 88
Student 2: 76
Student 3: 90
Student 4: 61
Student 5: 69

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples