0% found this document useful (0 votes)
7 views

Assignment 03

Uploaded by

Arpit Srivastava
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Assignment 03

Uploaded by

Arpit Srivastava
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Assignment – 03

1. Explain the concept of a pointer and how it is different from a regular variable. Provide
examples in C code to demonstrate how pointers are used to store addresses.
2. Write a program to illustrate pointer arithmetic by creating a pointer to an integer array and
using pointer arithmetic to traverse and display each element in the array.
3. What are the differences between ++ptr and ptr++ in pointer arithmetic? Explain with code
examples and describe situations where each might be used.
4. Write a program that uses multiple pointers to demonstrate the relationship between pointers
and multi-level pointers (e.g., pointer-to-pointer).
5. Explain and illustrate the use of const in pointer declarations (e.g., const int *ptr, int
*const ptr, and const int *const ptr). What does each declaration mean, and how
does it affect pointer usage?
6. Develop a C program to swap two integers using pointers. Explain why this method is preferred
over swapping values using a regular function call.
7. Write a program to reverse an array using pointers instead of indexing. Ensure the program
reads the array from the user, reverses it in place, and displays the reversed array.
8. Demonstrate how arrays and pointers are related by writing a program that accesses array
elements using both pointer arithmetic and array indexing. Explain any differences in
performance or flexibility.
9. Explain the concept of dynamic arrays in C. Write a program that allocates an integer array
dynamically, fills it with random values, displays the values, and then frees the allocated
memory.
10. Define a structure for a Student with members such as ID, name, and grade. Write a program
that allocates memory dynamically for an array of Student structures, assigns values to each
student, and displays their details.
11. Write a program to demonstrate accessing structure members via pointers. Define a structure
with several fields, create an instance of the structure, and use a pointer to modify its values.
12. Explain the significance of -> operator when working with pointers to structures in C. Write a
program that initializes a structure pointer and accesses its members using the -> operator.
13. Write a program that compares call by value and call by reference. Define a function that
modifies an integer passed to it by both methods and explain how the original value is affected.
14. Create a program that calculates the factorial of a number using call by reference. Explain why
call by reference is a better choice for this problem.
15. Explain the differences between malloc, calloc, and realloc. Write a program that
demonstrates each function by dynamically allocating memory for an integer array, re-
allocating memory when more space is needed, and freeing memory once done.
16. Write a program to dynamically create a 2D array using pointers and dynamic memory
allocation functions. Populate it with random values, print it, and ensure proper memory
deallocation.
17. Implement the selection sort algorithm in C and explain each step in the code with comments.
What is the time complexity of selection sort, and in what scenarios is it more effective?
18. Write a C program to sort an array using bubble sort. Include a flag to optimize the algorithm
for cases when the array is already sorted. Explain why this optimization is beneficial.
19. Develop a program to sort an array of integers using insertion sort. Trace through the program
with an example array, showing how the array changes with each pass.
20. Compare linear search and binary search in terms of time complexity and requirements. Write
separate functions in C for each search algorithm and demonstrate their usage on a sorted and
unsorted array.

You might also like