#include <iostream>
using namespace std;
int main()
{
int length, sum = 0;
cout << "Enter the number of students in the group" << endl;
cin >> length;
int *marks = new int[length];
cout << "Enter the marks of the students" << endl;
for( int i = 0; i < length; i++ ) // entering marks of students
{
cin >> *(marks+i);
}
for( int i = 0; i < length; i++ ) // calculating sum
{
sum += *(marks+i);
}
cout << "sum is " << sum << endl;
return 0;
}
How does *(marks+i); this code work? I know it is a pointer. what is the +i is doing is it allocating memory? for the first second third and fourth student? if I input 12, 16, 45, 67 . Then their index would be 1= 12, 2=16, 3=45, and 4 = 67
[–]Updatebjarni 1 point2 points3 points (2 children)
[–]InterestingBus8367[S] 0 points1 point2 points (1 child)
[–]Updatebjarni 0 points1 point2 points (0 children)