Programming in C_aarya
Programming in C_aarya
1. Define a function that compares two dates and returns which is earlier. Then
write code that prints the result using that function
(Use a struct date and compare year, month, day fields.)
2. Does the order of function definitions in a C program matter? How does a
function prototype help?
(Explain compiler flow and importance of prototypes for forward referencing.)
3. Write a program that defines and uses a macro and also accepts command-line
arguments
(Define a simple macro for PI or SQUARE(x) and use argc, argv.)
4. Define a structure named Vehicle and write a program to store data for 10
vehicles and sort them in descending order of price
(Use arrays of structures and sorting logic.)
5. Explain different storage classes in C with code examples: auto, static, extern,
register
(Show scope, lifetime, and where each is used.)
6. Define a structure for a hotel and write a function to print all hotels below a
specified room charge
(Use structure array, function, and if condition for filtering.)
Module 4 – Pointers and File Handling
1. Declare and explain how pointers are used in C. Write a program to access array
elements using a pointer
(Use int *ptr and pointer arithmetic like *(ptr + i).)
2. Write a program that processes strings using pointers, including pointer to
pointer and array of pointers
(Show string arrays and char *str[], char **ptr usage.)
3. Write a code snippet to open a file in write mode, check if it opened successfully,
and print an error if it fails
(Use FILE *fp = fopen("file.txt", "w"); and check with if(fp == NULL).)
4. Write programs for two people to access sample.txt, one for reading and
another for reading and writing simultaneously
(Use modes "r" and "r+"; show both operations with fopen, fgets, fprintf.)
5. Write a function that calculates roots of a quadratic equation using pointers to
pass coefficients a, b, c
(Use pointer parameters and apply the quadratic formula.)
6. Write a program to create a file for employee data, append data, delete a record
by making salary zero, and update salary
(Use file handling functions fopen, fprintf, fscanf, and handle logic for
update/delete.)