C Programming Exercises: Arrays and
Pointers
1. Reverse Array Using Pointers
Write a C program to reverse an array in-place using only pointers (no array indices).
Input:
arr = [1, 2, 3, 4, 5]
Output:
arr = [5, 4, 3, 2, 1]
2. Remove Duplicates from Array
Write a program to remove duplicate elements from an integer array, keeping only the first
occurrence of each element. Use pointers for manipulation.
Input:
arr = [1, 2, 3, 2, 4, 1, 5]
Output:
arr = [1, 2, 3, 4, 5]
3. Maximum Subarray Sum (Kadane’s Algorithm)
Implement Kadane’s algorithm using pointers to find the subarray with the maximum sum.
Input:
arr = [-2, -3, 4, -1, -2, 1, 5, -3]
Output:
7 (subarray = [4, -1, -2, 1, 5])
4. Find Missing Number in Sequence
Given an array of size n-1 containing numbers from 1 to n, find the missing number. Use
pointers.
Input:
arr = [1, 2, 4, 5], n = 5
Output:
3
5. Print Matrix in Spiral Order
Print the elements of an NxN matrix in spiral order using pointer arithmetic.
Input:
3x3 matrix:
123
456
789
Output:
[1, 2, 3, 6, 9, 8, 7, 4, 5]