Assignment
Assignment
Lab
Assignments
hours
3
Assignment
Q1. Write a C program that swaps two numbers using pointers. The program should contain a
function void swap(int *a, int *b) that swaps the values of two integers using their pointers.
Q2. Write a C program that reverses an array of integers using pointers. Implement a function
void reverse_array(int *arr, int n) to reverse the elements of the array using pointer manipulation.
Q3. Write a C program that copies a string from one location to another using pointers.
Implement a function void copy_string(char *source, char *destination) that copies the contents
of the source string to the destination string using pointers.
Q4. Write a C program to access elements of a 2D array using pointers. Implement a function
void access_2d_array(int *arr, int rows, int cols) that prints the elements of a 2D array using
pointer arithmetic.
Q5. Write a C program to find the sum of all elements in a 2D matrix using pointers. Implement
a function int matrix_sum(int *matrix, int rows, int cols) that calculates the sum of the elements
using pointer arithmetic.
Q 6. Write a C program that removes all vowels from a string using pointers. Implement a
function void remove_vowels(char *str) that modifies the string in-place by removing all vowels
(a, e, i, o, u).
Q 7. Write a C program to find the first occurrence of a substring within another string using
pointers. Implement a function char *find_substring(char *str, char *substr) that returns a pointer
to the first occurrence of substr in str, or NULL if substr is not found.
THE LNMIIT, Jaipur
Department of Computer Science & Engineering