What is an array in C? How does it differ from a pointer? Explain with an example.
How do you declare and initialize a 1D array of integers with size 10? What happens if you initialize it
with fewer elements than its size?
How are arrays stored in memory? Explain with a diagram how a 1D array int arr[5] = {1, 2, 3, 4, 5} is
stored.
What is the formula to calculate the memory address of the i-th element in a 1D array?
Why does sizeof(arr) give the total size of the array, while sizeof(ptr) gives the size of a pointer?
Write a C program to insert an element at a given position in a 1D array. How does this affect the
existing elements?
Write a C program to delete an element from a specific index in an array. How do you handle shifting
elements?
How is a 2D array stored in row-major order? Derive the formula to compute the address of arr[i][j].
Write a C program to transpose a square matrix (2D array). Can you do it in-place?
Given an array of integers, move all even numbers before odd numbers without using extra space.
Example:
Input: [3, 1, 2, 4, 6, 5] → Output: [2, 4, 6, 3, 1, 5]
Matrix Operations:
Implement a circular queue using an array. How do you handle overflow and underflow conditions?
Given an array, find the element that appears more than n/2 times (majority element).
How would you declare a 3D array in C? How is it stored in memory?
Can you have an array of pointers? Give an example where it is useful.
Programming Problems (Basic to Moderate)
1. Basic:
o Write a program to reverse a 1D array in place.
o Write a program to find the sum of all elements in a 2D array.
2. Moderate:
o Problem 3: Given an array of integers, move all zeros to the end while
maintaining the order of non-zero elements.
Example:
Input: [0, 1, 0, 3, 12] → Output: [1, 3, 12, 0, 0]
o Problem 4: Find the missing number in an array of size n containing
numbers from 1 to n+1 with one missing.
Example:
Input: [3, 1, 4, 5] → Output: 2 (since numbers are 1 to 5, missing 2).
o Problem 5: Given a 2D array, rotate it 90 degrees clockwise.
Example:
Input:
Copy
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
Output:
Copy
[7, 4, 1]
[8, 5, 2]
[9, 6, 3]
o Problem 6: Write a program to multiply two matrices (2D arrays) and store
the result in a third matrix.
o Problem 7: Given an array, find the contiguous subarray with the largest
sum (Kadane's Algorithm).
Example:
Input: [-2, 1, -3, 4, -1, 2, 1, -5, 4] → Output: 6 (from subarray [4, -1,
2, 1]).
o Problem 8: Remove duplicates from a sorted array in-place (no extra
space).
Example:
Input: [1, 1, 2, 2, 3] → Output: [1, 2, 3] (return new length 3).
o Problem 9: Given an array of integers, find two numbers that add up to a
specific target (assume exactly one solution).
Example:
Input: [2, 7, 11, 15], target = 9 → Output: [0, 1] (indices of 2 and 7)