Semester
Subject
Year
Tribhuwan University
2080
Bachelor Level / First Year / First Semester / Science
(C Programming)
Full Marks: 60
Pass Marks: 24
Time: 3 Hours
Candidates are required to give their answers in their own words as for as practicable.
The figures in the margin indicate full marks.
Long Answers Questions
An array is a collection of elements of the same data type stored in contiguous memory locations, accessed using a common name and an index (subscript).
Declaration Syntax:
data_type array_name[size];
Example: int marks[10]; — declares an array of 10 integers.
Key Properties:
arr[0], arr[1], ...When an array is passed to a function, the base address (address of the first element) is passed, not a copy of the entire array. This is called pass by reference.
Three ways to declare a function receiving an array:
void func(int *arr)void func(int arr[10])void func(int arr[])Important Points:
Example of function call:
int marks[10];
sort(marks, 10); // passing array name and size
#include <stdio.h>
// Function to sort array in ascending order (Bubble Sort)
void sortAscending(int arr[], int n) {
int i, j, temp;
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
// Swap the elements
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
int main() {
int arr[10], i;
// Input 10 integers
printf("Enter 10 integer numbers:\n");
for (i = 0; i < 10; i++) {
scanf("%d", &arr[i]);
}
// Call function to sort
sortAscending(arr, 10);
// Display sorted array
printf("Array in ascending order:\n");
for (i = 0; i < 10; i++) {
printf("%d ", arr[i]);
}
return 0;
}
Sample Output:
Enter 10 integer numbers:
45 12 89 33 7 56 21 98 64 10
Array in ascending order:
7 10 12 21 33 45 56 64 89 98
main()Conclusion: Arrays provide efficient storage for homogeneous data. When passed to functions, only the base address is transferred, allowing functions to directly modify the original array — making sorting operations simple and memory efficient.
Short Answers Questions