0% found this document useful (0 votes)
27 views6 pages

C ArraynPointer Assignment

The document is an assignment on C programming focusing on arrays and pointers, consisting of 100 questions divided into 50 multiple choice questions and 50 practical questions. It covers various topics such as array declaration, initialization, pointer operations, and interactions between arrays and pointers. Additionally, it includes practical programming tasks that require writing C programs to manipulate arrays and pointers.

Uploaded by

rp4009312
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views6 pages

C ArraynPointer Assignment

The document is an assignment on C programming focusing on arrays and pointers, consisting of 100 questions divided into 50 multiple choice questions and 50 practical questions. It covers various topics such as array declaration, initialization, pointer operations, and interactions between arrays and pointers. Additionally, it includes practical programming tasks that require writing C programs to manipulate arrays and pointers.

Uploaded by

rp4009312
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

C Programming Language: Arrays and Pointers - Assignment

By Vaibhav Bansal

Total Questions: 100

●​ MCQs (Multiple Choice Questions): 50 Questions


●​ Practical Questions: 50 Questions

Section 1: MCQs (50 Questions)

Arrays

1.​ What is the size of an array in C, when it is declared as int arr[10];?​

○​ A) 4
○​ B) 40
○​ C) 10
○​ D) Undefined
2.​ Which of the following is the correct way to declare a two-dimensional array in C?​

○​ A) int arr[10][20];
○​ B) int arr[10, 20];
○​ C) int arr(10)(20);
○​ D) int arr[10]:[20];
3.​ How do you access the first element of a one-dimensional array arr in C?​

○​ A) arr[0]
○​ B) arr[1]
○​ C) arr[-1]
○​ D) arr[0][0]
4.​ Which of the following is the correct way to initialize an array of integers arr with 5
elements?​

○​ A) int arr[5] = {1, 2, 3, 4, 5};


○​ B) int arr[] = {1, 2, 3, 4, 5};
○​ C) int arr[5] = {1, 2, 3};
○​ D) Both A and B
5.​ Which function is used to find the length of an array in C?​

○​ A) length()
○​ B) strlen()
○​ C) sizeof()
○​ D) sizeof(array)/sizeof(array[0])
6.​ How do you declare an array of 10 integers?​

○​ A) int arr[10];
○​ B) int arr[] = 10;
○​ C) int arr[10];[]
○​ D) array int[10];
7.​ What is the value of arr[4] if arr[] = {10, 20, 30, 40, 50};?​

○​ A) 10
○​ B) 40
○​ C) 50
○​ D) 30
8.​ What does the statement arr[3] = 10; do in an array arr[] = {5, 6, 7, 8,
9};?​

○​ A) Changes the value of arr[8] to 10


○​ B) Changes the value of arr[3] to 10
○​ C) Assigns 10 to the entire array
○​ D) Changes the size of the array
9.​ In a multi-dimensional array, how would you access the element at the second row
and third column in a 2D array arr[4][5]?​

○​ A) arr[1][2]
○​ B) arr[2][3]
○​ C) arr[1][3]
○​ D) arr[0][2]
10.​What will happen if an array is accessed outside of its bounds?​

○​ A) It will result in garbage value


○​ B) The program will throw a runtime error
○​ C) The program will exit unexpectedly
○​ D) Undefined behavior

Pointers

11.​What is the correct declaration of a pointer to an integer?​

○​ A) int *ptr;
○​ B) pointer int;
○​ C) ptr int;
○​ D) int ptr*;
12.​What does the operator * mean when used with pointers?​
○​ A) It’s a pointer declaration
○​ B) It’s a pointer dereferencing operator
○​ C) It’s used for multiplication
○​ D) None of the above
13.​What does the operator & mean in C when used with a variable?​

○​ A) It takes the address of the variable


○​ B) It dereferences the pointer
○​ C) It is used to find the size of a variable
○​ D) It multiplies the variable by 2
14.​What is the result of dereferencing a null pointer in C?​

○​ A) It will throw a segmentation fault


○​ B) It will return zero
○​ C) It will give an address of 0
○​ D) It will return a pointer to the first element in memory
15.​If int *p; and int x = 10; are declared, how do you assign the address of x to
p?​

○​ A) p = &x;
○​ B) p = *x;
○​ C) p = 10;
○​ D) *p = &x;
16.​What is a dangling pointer?​

○​ A) A pointer that points to valid memory


○​ B) A pointer that points to the wrong memory address
○​ C) A pointer that points to memory that has been freed
○​ D) A pointer that has been initialized
17.​Which of the following is true for a pointer?​

○​ A) A pointer stores the address of a variable


○​ B) A pointer stores the value of a variable
○​ C) A pointer can store a string only
○​ D) None of the above
18.​What does the following code do: *p++?​

○​ A) Dereferences the pointer and then increments it


○​ B) Increments the pointer and then dereferences it
○​ C) Both A and B
○​ D) Neither A nor B
19.​How do you dynamically allocate memory for an array of 10 integers using pointers?​

○​ A) int *arr = malloc(sizeof(int) * 10);


○​ B) int *arr = malloc(10 * sizeof(int));
○​ C) int *arr = calloc(10, sizeof(int));
○​ D) All of the above
20.​What is the purpose of free() function in C?​

○​ A) To allocate memory dynamically


○​ B) To release dynamically allocated memory
○​ C) To initialize pointers
○​ D) None of the above

Arrays and Pointers Interaction

21.​What is the relation between an array and a pointer in C?​

○​ A) An array is a constant pointer


○​ B) An array and pointer are completely different concepts
○​ C) An array can be treated as a pointer to its first element
○​ D) Both are types of references
22.​How do you pass an array to a function in C?​

○​ A) void func(int arr[]);


○​ B) void func(int *arr);
○​ C) void func(int arr[10]);
○​ D) All of the above
23.​When you pass an array to a function, what is actually passed?​

○​ A) The whole array


○​ B) A pointer to the first element of the array
○​ C) The size of the array
○​ D) A copy of the array
24.​Which of the following is true about passing arrays and pointers to functions?​

○​ A) Passing an array always involves copying its contents


○​ B) Passing a pointer is faster than passing an array
○​ C) Passing an array is more efficient than passing a pointer
○​ D) Passing an array always involves copying its address

What is the output of the following code snippet?​



int arr[] = {10, 20, 30};
printf("%d", *(arr + 1));

25.​
○​ A) 10
○​ B) 20
○​ C) 30
○​ D) Undefined behavior
26.​How would you use a pointer to modify the value of an array element inside a
function?​
○​ A) Pass the array as a pointer to the function
○​ B) Use a for loop in the function
○​ C) Use * operator to dereference the pointer in the function
○​ D) Both A and C
27.​Which of the following expressions represents the last element of an array arr[]?​

○​ A) arr[n]
○​ B) arr[n-1]
○​ C) arr[n] + 1
○​ D) arr[n-1] + 1
28.​What does the statement arr = arr + 1; do to an array pointer?​

○​ A) Increases the value of the array pointer by 1


○​ B) Moves the pointer to the next memory location of the array
○​ C) Both A and B
○​ D) None of the above
29.​In the context of pointers and arrays, what does arr[2] actually represent?​

○​ A) The value stored at the memory address of arr + 2


○​ B) The value stored at the first memory address of arr
○​ C) The address of arr[2]
○​ D) A pointer to the second element of arr
30.​How would you modify the value of the third element of the array arr[] = {5, 6,
7, 8}; using pointers?​

○​ A) *(arr + 2) = 10;
○​ B) arr[3] = 10;
○​ C) *arr[2] = 10;
○​ D) arr[2] = 10;

Section 2: Practical Questions (50 Questions)

Arrays

1.​ Write a C program to reverse an array of integers using a function.


2.​ Write a C program to find the largest and smallest elements in an array.
3.​ Write a C program to calculate the sum of all elements in an array.
4.​ Write a C program to sort an array of integers in ascending order using the bubble
sort algorithm.
5.​ Write a C program to find the second largest element in an array.
6.​ Write a C program to count the number of even and odd numbers in an array.
7.​ Write a C program to merge two sorted arrays into a single sorted array.
8.​ Write a C program to remove duplicates from an array.
9.​ Write a C program to rotate an array of integers to the left by n positions.
10.​Write a C program to transpose a 2D array (matrix).
11.​Write a C program to check if an array is a palindrome.
12.​Write a C program to find the median of an array.
13.​Write a C program to multiply two matrices using arrays.
14.​Write a C program to find the frequency of each element in an array.
15.​Write a C program to check if an array is sorted.
16.​Write a C program to split an array into two halves.
17.​Write a C program to find the intersection of two arrays.
18.​Write a C program to reverse the rows and columns of a matrix.
19.​Write a C program to find the sum of two matrices.
20.​Write a C program to compute the dot product of two arrays.

Pointers

21.​Write a C program to demonstrate the use of pointers with arrays.


22.​Write a C program to swap two variables using pointers.
23.​Write a C program to implement pointer arithmetic to traverse an array.
24.​Write a C program to calculate the length of a string using pointers.
25.​Write a C program to find the factorial of a number using a recursive function and
pointers.
26.​Write a C program to reverse a string using pointers.
27.​Write a C program to implement dynamic memory allocation for an array.
28.​Write a C program to implement a function that returns a pointer to an array.
29.​Write a C program to copy one string into another using pointers.
30.​Write a C program to compare two strings using pointers.
31.​Write a C program to demonstrate the use of a pointer to a structure.
32.​Write a C program to implement a linked list using pointers.
33.​Write a C program to delete an element in a linked list using pointers.
34.​Write a C program to find the length of a string using a pointer.
35.​Write a C program to calculate the sum of an array using pointers.
36.​Write a C program to print the elements of an array using pointer notation.
37.​Write a C program to dynamically allocate memory for a 2D array using pointers.
38.​Write a C program to create a pointer to a function and call it.
39.​Write a C program to create and manipulate a structure using pointers.
40.​Write a C program to implement a queue using pointers.
41.​Write a C program to implement a stack using pointers.
42.​Write a C program to reverse an array using pointer manipulation.
43.​Write a C program to implement a basic memory manager using pointers.
44.​Write a C program to find the minimum and maximum element in an array using
pointers.
45.​Write a C program to swap two numbers using a function that takes pointers.
46.​Write a C program to implement a circular linked list using pointers.
47.​Write a C program to implement a doubly linked list using pointers.
48.​Write a C program to find the factorial of a number using recursion and pointers.
49.​Write a C program to implement a pointer-based string reversal.
50.​Write a C program to allocate memory for a 3D matrix dynamically using pointers.

You might also like