---
title: "Pass student array; display passed students"
subject: "Computer Programming"
chapter: 7
key: "semester_1/computer_programming:pass-whole-array-student-info"
source: https://www.bctengineer.com/q/semester_1/computer_programming/pass-whole-array-student-info
site: BCT Engineering
---

# Pass student array; display passed students

Computer Programming · Chapter 7: Arrays and Strings

- Asked in: 2070 Chaitra, 2+8 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/pass-whole-array-student-info
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-7

## Question

Can we pass whole array element from function? Write a program to display only those students information which are passed. Use separate function to check the result of student. The information of students like Name, Roll No, Address and Marks are passed from main functions and pass to functions using array type arguments.

## Short answer

Parallel arrays (name[][20], roll[], addr[][20], marks[]) are passed by name. The function calls isPass(marks) to check marks>=40, then displays only passed students, using array arguments for direct access.

## Answer

Yes. The whole array is passed to a function by writing only its array name in the call. The function gets the address of the first element and can read or change every element. The size must be passed as another argument.

#### Program
The program keeps the student information in four parallel arrays (name, roll, address, marks) and passes them to `showPassed()`. That function calls a separate function `isPass()` to check the result of each student (passing marks = 40). Only the passed students are displayed.

```c
#include <stdio.h>
#define N 5

/* returns 1 if the student has passed (marks >= 40) */
int isPass(int marks)
{
    return marks >= 40;
}

void showPassed(char name[][20], int roll[], char addr[][20], int marks[], int n)
{
    printf("\nPassed students\n");
    printf("%-10s %-6s %-12s %s\n", "Name", "Roll", "Address", "Marks");
    for (int i = 0; i < n; i++)
        if (isPass(marks[i]))
            printf("%-10s %-6d %-12s %d\n", name[i], roll[i], addr[i], marks[i]);
}

int main(void)
{
    char name[N][20], addr[N][20];
    int roll[N], marks[N];
    for (int i = 0; i < N; i++) {
        printf("Student %d (name roll address marks): ", i + 1);
        scanf("%s %d %s %d", name[i], &roll[i], addr[i], &marks[i]);
    }
    showPassed(name, roll, addr, marks, N);
    return 0;
}
```

**Sample run**

Input: `Ram 1 Kathmandu 65 Sita 2 Lalitpur 32 Hari 3 Bhaktapur 48 Gita 4 Pokhara 39 Bibek 5 Butwal 71`

```text
Student 1 (name roll address marks): Student 2 (name roll address marks): Student 3 (name roll address marks): Student 4 (name roll address marks): Student 5 (name roll address marks): 
Passed students
Name       Roll   Address      Marks
Ram        1      Kathmandu    65
Hari       3      Bhaktapur    48
Bibek      5      Butwal       71
```

Sita (32) and Gita (39) have failed, so they are not displayed.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How is a whole array passed to a function?
   A. Pass each element in a loop only
   B. Write name[] in the call
   C. Pass the array by value copy
   D. Write only the array name in the call
   Answer: D. The name gives the address, so the function can read or change every element. (Key point: Passing whole array)

2. How is student information stored in the program?
   A. A single int array
   B. Four parallel arrays: name, roll, address and marks
   C. A union
   D. One string with all fields
   Answer: B. The same index i in each array belongs to one student. (Key point: Parallel arrays)

3. What does isPass(marks) do?
   A. Prints the student
   B. Returns the maximum mark
   C. Returns 1 if marks > 40
   D. Returns 1 if marks >= 40
   Answer: D. Passing marks is 40, so 40 itself passes. (Key point: Separate checker)

4. Which students are displayed in the sample run?
   A. Sita and Gita
   B. Ram, Hari and Bibek
   C. All five students
   D. Ram and Bibek only
   Answer: B. Marks 65, 48, 71 are >= 40; 32 and 39 fail. (Key point: Sample output)

## Related in Computer Programming

- [96 students record; pass marks](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-96-students-ioe-txt) — Computer Programming, chapter 10
- [Binary file of 48 students; highest mark](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-binary-48-students-highest) — Computer Programming, chapter 10
- [Pass array; transpose 3×3 matrix](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apass-array-transpose-3x3) — Computer Programming, chapter 7
- [Student records with two functions](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-student-read-display-functions) — Computer Programming, chapter 8
- [Pass 2D array; largest and smallest](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apass-2d-array-largest-smallest) — Computer Programming, chapter 7
- [Pass array; largest and smallest](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apass-array-largest-smallest) — Computer Programming, chapter 7

## Related in other subjects

- [Protected specifier; student/test/result program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aprotected-three-class-program) — Object Oriented Programming, chapter 6
- [File stream; student binary file program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afile-stream-student-binary) — Object Oriented Programming, chapter 8
- [Student file read/write and modify by roll](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Astudent-file-modify-roll) — Object Oriented Programming, chapter 8
- [Student file displayed in descending marks order](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Astudent-file-descending) — Object Oriented Programming, chapter 8
