Array
Part A: Multiple Choice Questions (1 Mark Each)
-
An array stores values of:
(a) Different data types
(b) Same data type
(c) Both same and different data type
(d) None of these
Answer: (b) -
Array index in C always starts from:
(a) 1
(b) -1
(c) 0
(d) 2
Answer: (c) -
Which of the following is the correct declaration of an integer array of size 5?
(a) int marks(5);
(b) int marks[5];
(c) int[5] marks;
(d) marks int[5];
Answer: (b) -
What is the size of an array
int num[10];
?
(a) 5 elements
(b) 9 elements
(c) 10 elements
(d) 11 elements
Answer: (c) -
Which of the following initializes an array correctly?
(a) int a[] = {10, 20, 30};
(b) int a[3] = {10, 20, 30};
(c) int a[5] = {10, 20, 30};
(d) All of these
Answer: (d) -
What does
marks[0]
represent?
(a) Last element of array
(b) First element of array
(c) Middle element of array
(d) None of these
Answer: (b) -
Which of the following is a two-dimensional array declaration?
(a) int a[2][3];
(b) int a(2,3);
(c) int a[2,3];
(d) int[2][3]a;
Answer: (a) -
A 2D array of
int a[4][5];
has how many total elements?
(a) 9
(b) 10
(c) 20
(d) 25
Answer: (c) -
Accessing elements in 2D array is done using:
(a) Single index
(b) Double index
(c) Pointer only
(d) None
Answer: (b) -
Which loop is best suited for traversing all elements of an array?
(a) while loop
(b) for loop
(c) do-while loop
(d) switch
Answer: (b) -
An array is stored in:
(a) Random memory
(b) Contiguous memory locations
(c) Separate memory blocks
(d) None of these
Answer: (b) -
The number of elements in
int a[3][4];
is:
(a) 7
(b) 10
(c) 12
(d) 15
Answer: (c) -
Which of the following is NOT an advantage of arrays?
(a) Easy access using index
(b) Efficient memory usage
(c) Can store values of different data types
(d) Code simplification
Answer: (c) -
Which statement is correct about array size?
(a) Can be changed during runtime
(b) Must be defined at declaration
(c) Can be infinite
(d) None
Answer: (b) -
Which of the following is an application of arrays?
(a) Storing student marks
(b) Storing timetable
(c) Image processing
(d) All of these
Answer: (d) -
In C, which symbol is used for array indexing?
(a) ( )
(b) { }
(c) [ ]
(d) < >
Answer: (c) -
Which of these is a one-dimensional array?
(a) int a[10];
(b) int a[5][5];
(c) int a[2][3][4];
(d) None
Answer: (a) -
If
int arr[5] = {1, 2, 3};
then arr[3] = ?
(a) 3
(b) 0
(c) 2
(d) Garbage value
Answer: (b) -
In
int a[2][3] = {{1,2,3}, {4,5,6}};
what is value of a[1][2]?
(a) 3
(b) 4
(c) 5
(d) 6
Answer: (d) -
What is the main difference between 1D and 2D arrays?
(a) 1D has multiple rows, 2D has one row
(b) 1D is linear, 2D is tabular (rows and columns)
(c) 1D uses two indices, 2D uses one index
(d) None
Answer: (b)
Part B: Very Short Answer Questions (1 Mark Each)
Q1. Define an array.
Ans:- An array is a collection of elements of the same data type stored in contiguous memory locations and accessed using an index.
Q2. What is the starting index of an array?
Ans:- The starting index of an array is 0.
Q3. Write the syntax for declaring a one-dimensional array.
Ans:- data_type array_name[size];
Example: int marks[5];
Q4. How many elements are there in int arr[5]?
Ans:- There are 5 elements in arr[5]
.
Q5. Give one example of array initialization.
Ans:- int num[3] = {10, 20, 30};
Q6. Which header file is needed for printf() in C?
Ans:- The header file is <stdio.h>.
Q7. What is a two-dimensional array?
Ans:- A two-dimensional array is an array of arrays where elements are stored in rows and columns.
Q8. Write any one real-life use of 1D array.
Ans:- Storing marks of students in a class.
Q9. Write any one real-life use of 2D array.
Ans:- Representing a timetable in rows and columns.
Q10. Write the difference between declaration and initialization of an array.
Ans:-
-
Declaration: Defining the array with size (e.g.,
int arr[5];
). -
Initialization: Assigning values at the time of declaration (e.g.,
int arr[5] = {10, 20, 30, 40, 50};
).
Part C: Short Answer Questions (2–3 Marks Each)
Q1. Write advantages of one-dimensional arrays.
Ans:-
-
Efficient storage of multiple values of the same type.
-
Easy access to elements using index.
-
Simplifies code with loops.
-
Stored in contiguous memory locations.
Q2. Write advantages of two-dimensional arrays.
Ans:-
-
Stores tabular data in rows and columns.
-
Simplifies code for handling matrices and tables.
-
Efficient memory usage.
-
Useful in complex applications like games, images, and schedules.
Q3. Write a C program to input and display 5 numbers using an array.
Ans:-
Q4. Differentiate between one-dimensional and two-dimensional arrays.
Ans:-
-
1D Array: Stores elements in a single row. Example:
int marks[5];
-
2D Array: Stores elements in rows and columns. Example:
int marks[2][3];
Q5. What happens if we do not initialize all elements of an array?
Ans:- The remaining elements are automatically initialized to 0.
Part D: Long Answer Questions (5 Marks Each)
Q1. Explain one-dimensional arrays with syntax, example, advantages, and uses.
Ans:-
-
Definition: A linear collection of elements stored in contiguous memory.
-
Syntax:
data_type array_name[size];
-
Example:
int marks[5] = {90, 80, 70, 60, 50};
-
Advantages: Efficient storage, easy access, loop-based processing.
-
Uses: Storing marks, daily temperatures, roll numbers, sales data.
Q2. Explain two-dimensional arrays with syntax, example, advantages, and uses.
Ans:-
-
Definition: An array of arrays where data is arranged in rows and columns.
-
Syntax:
data_type array_name[rows][columns];
-
Example:
-
Advantages: Tabular storage, efficient for matrices, easy access.
-
Uses: Storing tables, timetables, games (chess), image data, mathematical matrices.
Q3. Write a C program to store marks of 5 students in an array and print them.
Ans:-
Q4. Write a program to store and print elements of a 2×3 matrix using a 2D array.
Ans:-
Q5. Compare one-dimensional and two-dimensional arrays with examples.
Ans:-
-
One-Dimensional Array:
-
Stores data in a single row.
-
Example:
int marks[5] = {10, 20, 30, 40, 50};
-
Use: Storing marks, roll numbers, daily temperatures.
-
-
Two-Dimensional Array:
-
Stores data in rows and columns.
-
Example:
-
Use: Timetables, matrices, games, images.
-
No comments:
Post a Comment