Exam Questions for Programming Problem Solving

Preparing for your programming exams? Here’s a set of essential questions to test your understanding of key concepts in C programming and problem-solving. These questions cover fundamental topics like header files, loops, storage classes, recursion, strings, structures, unions, function calls, sorting algorithms, pointers, and file handling.

3/26/20252 min read

1. What is the purpose of the stdio.h header file in C?

The stdio.h (Standard Input Output) header file provides declarations for standard input and output functions in C. It includes functions like printf(), scanf(), fopen(), and fclose(), enabling basic I/O operations, file handling, and console interactions.

2. Explain the difference between break and continue statements within a loop.
  • break: Terminates the loop immediately, exiting the entire loop structure.

  • continue: Skips the remaining code in the current iteration and proceeds to the next iteration of the loop.

3. What are storage classes in C?

Storage classes define the scope, lifetime, and visibility of variables and functions. The four primary storage classes are:

  • auto: Default for local variables (limited to the block where they are declared).

  • register: Suggests storing the variable in a CPU register for faster access.

  • static: Preserves the variable's value between function calls and limits scope to the file/block.

  • extern: Extends the visibility of global variables across multiple files.

4. Describe the concept of recursion.

Recursion is a programming technique where a function calls itself to solve a problem by breaking it into smaller, similar subproblems. It requires:

  • A base case to terminate the recursion.

  • A recursive case that reduces the problem size.
    If not controlled properly, recursion can lead to stack overflow due to excessive function calls.

5. How are strings declared and initialized in C?

In C, strings are arrays of characters terminated by a null character (\0). They can be declared and initialized in multiple ways:

  • Direct assignment: char str[] = "Hello"; (automatically adds \0).

  • Explicit initialization: char str[6] = {'H','e','l','l','o','\0'};.

6. What is the difference between a structure and a union in C?

FeatureStructure (struct)Union (union)Memory AllocationEach member has separate memory.All members share the same memory (size = largest member).AccessAll members can be accessed independently.Only one member can be accessed at a time.Use CaseUsed for grouping different data types.Used for memory efficiency when only one member is needed.

7. Explain the difference between call-by-value and call-by-reference.

Call-by-ValueCall-by-ReferencePasses a copy of the argument.Passes the memory address of the argument.Modifications inside the function do not affect the original value.Modifications inside the function affect the original value.Uses normal variables.Uses pointers.

8. What is the time complexity of Bubble Sort in the best-case scenario?
  • Best Case: O(n) (when the input array is already sorted).

  • Worst Case: O(n²) (when the array is in reverse order).

9. What is a pointer to an integer in C?

A pointer to an integer is a variable that stores the memory address of an integer. It allows indirect access and manipulation of the integer’s value.

10. What is the return type of the fopen() function?

The fopen() function returns a FILE* (pointer to a FILE object) if successful. If the file cannot be opened, it returns NULL.

Conclusion

These theory-based questions cover fundamental programming concepts crucial for exams. Understanding these topics will strengthen your problem-solving skills and conceptual clarity.

Best of luck with your exams! 📚