Important C Programming Questions - Semester 2 (FY BSc CS)
Functions and Recursion
- Explain function declaration, definition, and call with example.
- Differentiate between call by value and call by reference.
- Write a program to find factorial using recursion.
- Write a program to check if a number is prime using a function.
- Explain scope and lifetime of variables in functions.
Arrays and Strings
- Write a program to find the largest element in an array.
- Write a program to sort an array in ascending order.
- Explain 2D arrays with syntax and example.
- What are strings? How are they declared and initialized in C?
- Write a program to reverse a string without using string functions.
- Explain any three standard string library functions with syntax.
Pointers
- Define pointers. How are they declared and initialized?
- Write a program to swap two numbers using pointers.
- Difference between array and pointer.
- Write a program to find the sum of elements in an array using pointers.
- Explain pointer to pointer with example.
Structures and Unions
- Define structure. How is it different from array?
- Write a program to accept and display student details using structure.
- What is a nested structure? Explain with example.
- Define union. Difference between structure and union.
- Explain array of structures with an example.
File Handling
- Explain how to open, read, write, and close a file in C.
- Difference between text file and binary file.
- Write a program to write and read data from a text file.
- Explain file I/O functions: fopen(), fclose(), fprintf(), fscanf().
- Write a program to count number of characters, words, and lines in a file.
Dynamic Memory Allocation
- What is dynamic memory allocation? List related functions.
- Difference between malloc(), calloc(), realloc(), and free().
- Write a program to allocate memory for an array using malloc().
- Explain memory leak and how to avoid it.
- Why is free() function important?