Lesson 60 of 60 – C Final Quiz
100%

C Programming Final Quiz

Congratulations! You have reached the final lesson of the C Programming course. This lesson provides a complete revision of important C concepts covered throughout the tutorial.

Final Quiz: Review each question carefully and test your understanding of C programming fundamentals, control structures, functions, arrays, strings, pointers, structures, memory, files, and practical programming.

1. What is C?

C is a general-purpose programming language widely used for system programming, embedded programming, and application development.

#include <stdio.h>

int main()
{
    printf("Hello C");

    return 0;
}

2. Who Developed C?

C was developed by Dennis Ritchie at Bell Labs in the early 1970s.

C became highly influential in systems programming and has influenced many later programming languages.

3. What is the main() Function?

The main() function is the designated entry point of a hosted C program.

int main()
{
    return 0;
}

Program execution begins by calling main().

4. What is a Variable?

A variable is a named object used to store a value that can be changed during program execution.

int age = 20;

age = 21;

5. What is a Constant?

A constant represents a value that is not intended to be modified through the identifier during the program's execution.

const int DAYS = 7;

The const qualifier can be used to create an object that should not be modified through that identifier.

6. What is a Data Type?

A data type determines the kind of value an object can represent and influences its storage and operations.

int age;
float price;
char grade;
double distance;

7. What is an Operator?

An operator is a symbol that performs an operation on one or more operands.

int sum = a + b;
int result = a * b;

C provides arithmetic, relational, logical, assignment, bitwise, conditional, and other operators.

8. What Does the if Statement Do?

if(age >= 18)
{
    printf("Adult");
}

The if statement executes a block when its controlling expression evaluates to a nonzero value.

9. What is the switch Statement?

switch(choice)
{
    case 1:
        printf("One");
        break;

    case 2:
        printf("Two");
        break;

    default:
        printf("Other");
}

The switch statement selects among labeled cases based on the value of its controlling expression.

10. What is a for Loop?

for(int i = 1; i <= 5; i++)
{
    printf("%d ", i);
}

A for loop is commonly used when initialization, a condition, and an iteration expression are needed for repeated execution.

11. What is a while Loop?

int i = 1;

while(i <= 5)
{
    printf("%d ", i);
    i++;
}

The condition of a while loop is tested before each iteration.

12. What is a do-while Loop?

int i = 1;

do
{
    printf("%d ", i);
    i++;
}
while(i <= 5);

A do-while loop executes its body before testing its condition, so the body executes at least once.

13. What Does break Do?

for(int i = 1; i <= 10; i++)
{
    if(i == 5)
        break;

    printf("%d ", i);
}

The break statement terminates the nearest enclosing loop or switch statement.

14. What Does continue Do?

for(int i = 1; i <= 5; i++)
{
    if(i == 3)
        continue;

    printf("%d ", i);
}

The continue statement skips the rest of the current loop iteration and proceeds with the next iteration according to the loop.

15. What is a Function?

int add(int a, int b)
{
    return a + b;
}

A function is a named block of code that performs a particular operation and can be called from other parts of a program.

16. What is Recursion?

int factorial(int n)
{
    if(n <= 1)
        return 1;

    return n * factorial(n - 1);
}

Recursion occurs when a function directly or indirectly calls itself. A recursive function needs an appropriate base case.

17. What is an Array?

int numbers[5] = {10, 20, 30, 40, 50};

An array stores multiple elements of the same type in contiguous storage. C array indexing starts at 0.

18. What is a String in C?

char name[] = "Rahul";

A C string is a sequence of characters terminated by a null character '\0'.

String-related functions are commonly provided by string.h.

19. What is a Pointer?

int number = 10;
int *ptr = &number;

printf("%d", *ptr);

A pointer stores an address. The unary * operator can be used to access the object referred to by a valid pointer.

20. What is a Structure?

struct Student
{
    int id;
    char name[50];
    float marks;
};

A structure groups related members that may have different data types.

21. What is a Union?

union Data
{
    int number;
    float price;
    char letter;
};

Members of a union share the same storage. At a given time, the stored representation should be interpreted according to the member being used, subject to the C language rules.

22. What is typedef?

typedef unsigned int uint;

uint age = 20;

The typedef keyword creates an alternative name for an existing type.

23. What is Dynamic Memory Allocation?

int *numbers;

numbers = malloc(5 * sizeof(int));

if(numbers != NULL)
{
    /* use memory */

    free(numbers);
}

Dynamic memory can be allocated during program execution using functions such as malloc(), calloc(), and realloc(), and released with free().

24. What is File Handling?

FILE *file;

file = fopen("data.txt", "r");

if(file != NULL)
{
    /* read file */

    fclose(file);
}

File handling allows a C program to read from and write to files using facilities provided by stdio.h.

25. What is a Header File?

#include <stdio.h>

Header files commonly contain declarations, macros, and type definitions that can be shared between source files.

Project headers are commonly included using:

#include "student.h"

26. What is Error Handling?

FILE *file = fopen("data.txt", "r");

if(file == NULL)
{
    perror("File error");
}

C programs commonly handle errors using return values, null-pointer checks, errno, perror(), and appropriate validation.

27. What is the Preprocessor?

#include <stdio.h>
#define MAX 100

The C preprocessor processes directives such as #include, #define, and conditional compilation directives before the main compilation stage.

28. What is Modular Programming?

Modular programming divides a larger program into smaller, organized components.

project/
│
├── main.c
├── student.c
├── student.h
├── utility.c
└── utility.h

Functions, source files, and header files can help organize a C project into manageable modules.

29. Final Practical Challenge

Create a complete C application using the concepts learned in this course.

  1. Use structures to store records.
  2. Use functions for different operations.
  3. Use arrays to store multiple records.
  4. Use conditions for decision-making.
  5. Use loops for repeated operations.
  6. Use pointers where appropriate.
  7. Validate user input.
  8. Use file handling to save data.
  9. Use a custom header file.
  10. Organize the program into multiple source files.

This challenge will help you combine the major concepts of C programming into one practical application.

30. Course Completion

🎉 Congratulations!

You have completed the complete 60-lesson C Programming tutorial.

You have studied:

  • C fundamentals
  • Variables and data types
  • Operators
  • Conditions
  • Loops
  • Functions
  • Recursion
  • Arrays
  • Strings
  • Pointers
  • Structures
  • Unions
  • Enumerations
  • Dynamic memory
  • File handling
  • Command-line arguments
  • Preprocessor directives
  • Header files
  • Error handling
  • Practical programs
  • Mini projects

Continue practicing by building your own C programs and gradually increasing their complexity.

📌 Final Revision Points

  • Every C program is built from statements, expressions, declarations, and functions.
  • Variables store values and data types describe their types.
  • Operators perform calculations and comparisons.
  • Conditions control decision-making.
  • Loops perform repeated operations.
  • Functions make programs reusable and organized.
  • Arrays store multiple elements of the same type.
  • Strings are null-terminated character sequences.
  • Pointers store addresses and enable indirect access to objects.
  • Structures group related members of different types.
  • Dynamic memory must be managed carefully.
  • Files allow data to be stored outside program memory.
  • Header files help share declarations between source files.
  • Error handling makes programs more reliable.
  • Practical projects are essential for developing programming skills.

🧠 Final Quiz

Question 1: Which function is the designated entry point of a hosted C program?





Question 2: Which operator is used to obtain the address of an object?





Question 3: Which keyword creates an alternative name for an existing type?





Question 4: Which function is used to release memory allocated dynamically with malloc()?





Question 5: Which statement is used to select among multiple constant cases based on an expression's value?





Question 6: What terminates a C string?





Question 7: Which keyword is used to define a structure?





Question 8: Which preprocessor directive is commonly used to include a header file?





Question 9: Which function is commonly used to open a file?





Question 10: Which function is commonly used to print an error message based on errno?