Array and Pointer
Array and Pointer
NOTE:
LAB OBJECTIVES
At the end of this lab activity, the students should be able to:
Term 2420 1
CCP4114 - PROGRAM DESIGN LAB 8
ARRAY
QUESTION 1
This program will calculate the average of quiz marks for students.
In main():
o Declare an empty array called test for 4 students with 3 quizzes each.
o Call function get_marks(…) and pass the test array as argument.
o Use while loops:
Calculate the total marks and average for each students.
Call function display(…) and pass the necessary arguments.
In function get_marks(…):
o Use for loops to ask each user to enter their marks.
o The marks are stored into the array.
In function display(…):
o Print the average of each students.
(There are no loops here, just a print statement.)
Sample Output
Student 1 :
Enter quiz 1 marks : 6.5
Enter quiz 2 marks : 8
Enter quiz 3 marks : 10
Student 2 :
Enter quiz 1 marks : 7.5
Enter quiz 2 marks : 7
Enter quiz 3 marks : 8
Student 3 :
Enter quiz 1 marks : 4
Enter quiz 2 marks : 8
Enter quiz 3 marks : 10
Student 4 :
Enter quiz 1 marks : 6
Enter quiz 2 marks : 7
Enter quiz 3 marks : 6.5
Term 2420 2
CCP4114 - PROGRAM DESIGN LAB 8
POINTER
QUESTION 2
Trace the following code segments and write the outputs generated by them.
void Q(int z)
{
z += x;
print(z);
}
void P(int *y)
{
int x = *y + 8;
Q(x);
*y = x - 3 * x;
print(x);
}
void print(int val)
{
printf("\n%d", val);
}
void main()
{
x = 5;
P(&x);
print(x);
}
Term 2420 3
CCP4114 - PROGRAM DESIGN LAB 8
a = &numbers[3];
b = numbers;
Term 2420 4