C Programming Interview Questions (2025)

Zero
ZeroSpace (admin)

Feb 23, 2025, 04:52 PM

20 Min

469

0

0


C Programming Interview Questions (2025)

At Bell Labs, Dennis Ritchie developed the C programming language between 1971 and 1973. C is a mid-level structured-oriented programming and general-purpose programming. It is one of the oldest and most popular programming languages. There are many applications in which C programming language is used, including language compilers, operating systems, assemblers, network drivers, text editors, print spoolers, modern applications, language interpreters, databases, and utilities | Source: BlogForgeTM


In this article, you will get the frequently and most asked C programming interview questions and answers at the fresher and experienced levels.

Preparing for a C programming interview requires a solid understanding of core concepts.

So, let us start with Questions for freshers.

C Programming Interview Questions – For Freshers

1. Why is C called a mid-level programming language?

Due to its ability to support both low-level and high-level features, C is considered a middle-level language. It is both an assembly-level language, i.e. a low-level language, and a higher-level language. Programs that are written in C are converted into assembly code, and they support pointer arithmetic (low-level) while being machine-independent (high-level). Therefore, C is often referred to as a middle-level language. C can be used to write operating systems and menu-driven consumer billing systems.

2. What are the features of the C programming language? 

features of C programming languageFeatures of C Programming language

For more information, refer to the article – Features of C programming language.

3. What are basic data types supported in the C Programming Language?

Each variable in C has an associated data type. Each data type requires different amounts of memory and has some specific operations which can be performed over it. It specifies the type of data that the variable can store like integer, character, floating, double, etc. In C data types are broadly classified into 4 categories:

  • Primitive data types: Primitive data types can be further classified into integer, and floating data types.
    • Void Types: Void data types come under primitive data types. Void data types provide no result to their caller and have no value associated with them.
  • User Defined data types: These data types are defined by the user to make the program more readable.
  • Derived data types: Data types that are derived from primitive or built-in data types.
Data Types in CData Types in C
For more information, refer to the article – Data Types in C

4. What are tokens in C?

Tokens are identifiers or the smallest single unit in a program that is meaningful to the compiler. In C we have the following tokens:

  • Keywords: Predefined or reserved words in the C programming language. Every keyword is meant to perform a specific task in a program. C Programming language supports 32 keywords.
  • Identifiers: Identifiers are user-defined names that consist of an arbitrarily long sequence of digits or letters with either a letter or the underscore (_) as a first Character. Identifier names can’t be equal to any reserved keywords in the C programming language. There are a set of rules which a programmer must follow in order to name an identifier in C.
  • Constants: Constants are normal variables that cannot be modified in the program once they are defined. Constants refer to a fixed value. They are also referred to as literals.
  • Strings: Strings in C are an array of characters that end with a null character (‘\0). Null character indicates the end of the string; 
  • Special Symbols: Some special symbols in C have some special meaning and thus, they cannot be used for any other purpose in the program. # = {} () , * ; [] are the special symbols in C programming language.
  • Operators: Symbols that trigger an action when they are applied to any variable or any other object. Unary, Binary, and ternary operators are used in the C Programming language.
For more information, refer to the article – Tokens in C

5. What do you mean by the scope of the variable?

Scope in a programming language is the block or a region where a defined variable will have its existence and beyond that region, the variable is automatically destroyed.  Every variable has its defined scope. In simple terms, the scope of a variable is equal to its life in the program. The variable can be declared in three places These are:

  • Local Variables: Inside a given function or a block
  • Global Variables: Out of all functions globally inside the program.
  • Formal Parameters: In-function parameters only.
For more information, refer to the article – Scope in C

6. What are preprocessor directives in C?

In C preprocessor directives are considered the built-in predefined functions or macros that act as a directive to the compiler and are executed before the program execution. There are multiple steps involved in writing and executing a program in C. Main types of Preprocessor Directives are Macros, File Inclusion, Conditional Compilation, and Other directives like #undef, #pragma, etc.

Processor in CProcessor in C

For more information, refer to the article – Preprocessor Directives in C 

7. What is the use of static variables in C?

Static variables in the C programming language are used to preserve the data values between function calls even after they are out of their scope. Static variables preserve their values in their scope and they can be used again in the program without initializing again. Static variables have an initial value assigned to 0 without initialization.

// C program to print initial
// value of static variable
#include <stdio.h>
int main()
{
    static int var;
    int x;
    printf("Initial value of static variable %d\n", var);
    printf("Initial value of variable without static %d",
           x);
    return 0;
}

Output
Initial value of static variable 0
Initial value of variable without static 0
For more information, refer to the article – Static Variables in C

8. What is the difference between malloc() and calloc() in the C programming language?

calloc() and malloc() library functions are used to allocate dynamic memory. Dynamic memory is the memory that is allocated during the runtime of the program from the heap segment. “stdlib.h” is the header file that is used to facilitate dynamic memory allocation in the C Programming language.

Parameter Malloc() Calloc()
Definition It is a function that creates one block of memory of a fixed size. It is a function that assigns more than one block of memory to a single variable.
Number of arguments It only takes one argument. It takes two arguments.
Speed malloc() function is faster than calloc(). calloc() is slower than malloc().
Efficiency It has high time efficiency. It has low time efficiency.
Usage It is used to indicate memory allocation. It is used to indicate contiguous memory allocation.
For more information, refer to the article – Dynamic Memory Allocation in C using malloc(), calloc(), free(), and realloc()

9. What do you mean by dangling pointers and how are dangling pointers different from memory leaks in C programming?

Pointers pointing to deallocated memory blocks in C Programming are known as dangling pointers i.e, whenever a pointer is pointing to a memory location and In case the variable is deleted and the pointer still points to that same memory location then it is known as a dangling pointer variable. 
In C programming memory leak occurs when we allocate memory with the help of the malloc() or calloc() library function, but we forget to free the allocated memory with the help of the free() library function. Memory leak causes the program to use an undefined amount of memory from the RAM which makes it unavailable for other running programs this causes our program to crash.

10. Write a program to convert a number to a string with the help of sprintf() function in the C library.

// C program to convert number to
// string using sprintf()
#include <stdio.h>
#include <string.h>

// Driver code
int main()
{
    char res[20];
    float a = 32.23;
    sprintf(res, "%f", a);
    printf("\nThe string for the num is %s", res);
    return 0;
}

Output
The string for the num is 32.230000
For more information, refer to the article – sprintf() in C

11. What is recursion in C?

Recursion is the process of making the function call itself directly or indirectly. A recursive function solves a particular problem by calling a copy of itself and solving smaller subproblems that sum up the original problems. Recursion helps to reduce the length of code and make it more understandable. The recursive function uses a LIFO ( Last In First Out ) structure like a stack. Every recursive call in the program requires extra space in the stack memory.

For more information, refer to the article – Recursion

12. What is the difference between the local and global variables in C?

Local variables are declared inside a block or function but global variables are declared outside the block or function to be accessed globally.

Local Variables Global Variables
Declared inside a block or a function. Variables that are declared outside the block or a function.
By default, variables store a garbage value. By default value of the global value is zero.
The life of the local variables is destroyed after the block or a function. The life of the global variable exists until the program is executed.
Variables are stored inside the stack unless they are specified by the programmer. The storage location of the global variable is decided by the compiler.
To access the local variables in other functions parameter passing is required. No parameter passing is required. They are globally visible throughout the program.

13. What are pointers and their uses? 

Pointers are used to store the address of the variable or a memory location. Pointer can also be used to refer to another pointer function. The main purpose of the pointer is to save memory space and increase execution time. Uses of pointers are:

  • To pass arguments by reference
  • For accessing array elements
  • To return multiple values
  • Dynamic memory allocation
  • To implement data structures
  • To do system-level programming where memory addresses are useful
  •  
Working of PointerWorking of Pointer

For more information, refer to the article – Pointer Uses in C.

14. What is typedef in C?

In C programming, typedef is a keyword that defines an alias for an existing type. Whether it is an integer variable, function parameter, or structure declaration, typedef will shorten the name.

Syntax:

typedef <existing-type> <alias-name>Here,
  • existing type is already given a name. 
  • alias name is the new name for the existing variable.

Example:

typedef long long ll

15. What are loops and how can we create an infinite loop in C?

Loops are used to execute a block of statements repeatedly. The statement which is to be repeated will be executed n times inside the loop until the given condition is reached. There are two types of loops Entry controlled and Exit-controlled loops in the C programming language. An Infinite loop is a piece of code that lacks a functional exit. So, it repeats indefinitely. There can be only two things when there is an infinite loop in the program. One it was designed to loop endlessly until the condition is met within the loop. Another can be wrong or unsatisfied break conditions in the program.

Types of LoopsTypes of Loops

 Below is the program for infinite loop in C:

// C program for infinite loop
// using for, while, do-while
#include <stdio.h>

// Driver code
int main()
{
    for (;;) {
        printf("Infinite-loop\n");
    }

    while (1) {
        printf("Infinite-loop\n");
    }

    do {
        printf("Infinite-loop\n");
    } while (1);

    return 0;
}
 

For more information, refer to the article – Loops in C

16. What is the difference between type casting and type conversion?

Type Casting Type Conversion
The data type is converted to another data type by a programmer with the help of a casting operator. The data type is converted to another data by a compiler.
It can be applied to both compatible data types as well as incompatible data types. Type conversion can only be applied to only compatible data types.
In Type casting in order to cast the data type into another data type, a caste operator is needed In type conversion, there is no need for a casting operator.
Type casting is more efficient and reliable. Type conversion is less efficient and less reliable than type casting.
Type casting takes place during the program design by the programmer. Type conversion is done at compile time.
Syntax: 
destination_data_type = (target_data_type) variable_to_be_converted;
Syntax: 
int a = 20; float b; b = a; // a = 20.0000
 
For more information, refer to the article – Type Casting and Type Conversion

17. What are header files and their uses?

C language has numerous libraries which contain predefined functions to make programming easier. Header files contain predefined standard library functions. All header files must have a ‘.h’ extension. Header files contain function definitions, data type definitions, and macros which can be imported with the help of the preprocessor directive ‘#include’. Preprocessor directives instruct the compiler that these files are needed to be processed before the compilation. 
There are two types of header files i.e, User-defined header files and Pre-existing header files. For example, if our code needs to take input from the user and print desired output to the screen then ‘stdio.h’ header file must be included in the program as #include<stdio.h>. This header file contains functions like scanf() and printf() which are used to take input from the user and print the content.

For more information, refer to the article – Header Files in C

18. What are the functions and their types?

The function is a block of code that is used to perform a task multiple times rather than writing it out multiple times in our program. Functions avoid repetition of code and increase the readability of the program. Modifying a program becomes easier with the help of function and hence reduces the chances of error. There are two types of functions:

  • User-defined Functions: Functions that are defined by the user to reduce the complexity of big programs. They are built only to satisfy the condition in which the user is facing issues and are commonly known as “tailor-made functions”.
  • Built-in Functions: Library functions are provided by the compiler package and consist of special functions with special and different meanings. These functions give programmers an edge as we can directly use them without defining them.
For more information, refer to the article – Functions in C

19. What is the difference between macro and functions?

A macro is a name that is given to a block of C statements as a pre-processor directive. Macro is defined with the pre-processor directive. Macros are pre-processed which means that all the macros would be preprocessed before the compilation of our program. However, functions are not preprocessed but compiled. 

Macro Function
Macros are preprocessed. Functions are compiled.
Code length is increased using macro. Code length remains unaffected using function.
Execution speed using a macro is faster. Execution speed using function is slower.
The macro name is replaced by the macro value before compilation. Transfer of control takes place during the function call.
Macro doesn’t check any Compile-Time Errors. Function check Compile-time errors.
For more information, refer to the article – Macro vs Functions

C Programming Interview Questions

C Programming Interview Questions – Intermediate Level

20. How to convert a string to numbers in C?

In C we have 2 main methods to convert strings to numbers i.e, Using string stream, Using stoi() library Function or using atoi() library function. 

  • sscanf(): It reads input from a string rather than standard input.
  • stoi() or atoi(): These functions takes a string literal or a character array as an argument and an integer value is returned.
For more information, refer to the article – String to Numbers in C

21. What are reserved keywords?

Every keyword is meant to perform a specific task in a program. Their meaning is already defined and cannot be used for purposes other than what they are originally intended for. C Programming language supports 32 keywords. Some examples of reserved keywords are auto, else, if, long, int, switch, typedef, etc.

For more information, refer to the article – Variables and Keywords in C

22. What is a structure?

The structure is a keyword that is used to create user-defined data types. The structure allows storing multiple types of data in a single unit. The structure members can only be accessed through the structure variable.

Example:

struct student
{
   char name[20];
   int roll_no;
  char address[20];
  char branch[20];
};

Below is the C program to implement structure:

// C Program to show the
// use of structure
#include <stdio.h>
#include <string.h>

// Structure student declared
struct student {
    char name[20];
    int roll_no;
    char address[50];
    char branch[50];
};

// Driver code
int main()
{
    struct student obj;

    strcpy(obj.name, "Kamlesh_Joshi");
    obj.roll_no = 27;
    strcpy(obj.address, "Haldwani");
    strcpy(obj.branch, "Computer Science
     And Engineering");

    // Accessing members of student obj
    printf("Name: %s\n", obj.name);
    printf("Roll_No: %d \n", obj.roll_no);
    printf("Address: %s\n", obj.address);
    printf("Branch: %s", obj.branch);

    return 0;
}
 
 

Output
Name: Kamlesh_Joshi
Roll_No: 27 
Address: Haldwani
Branch: Computer Science And Engineering
For more information, refer to the article – Structure in C

23. What is union?

A union is a user-defined data type that allows users to store multiple types of data in a single unit. However, a union does not occupy the sum of the memory of all members. It holds the memory of the largest member only. Since the union allocates one common space for all the members we can access only a single variable at a time. The union can be useful in many situations where we want to use the same memory for two or more members.

Syntax:

union name_of_union
{
   data_type name;
   data_type name;
};
For more information, refer to the article – Union in C

24. What is an r-value and value?

An “l-value” refers to an object with an identifiable location in memory (i.e. having an address).  An “l-value” will appear either on the right or left side of the assignment operator(=). An “r-value” is a data value stored in memory at a given address. An “r-value” refers to an object without an identifiable location in memory (i.e. without an address). An “r-value” is an expression that cannot be assigned a value, therefore it can only exist on the right side of an assignment operator (=).

Example:

int val = 20;
//Here, val is the ‘l-value’, and 20 is the ‘r-value’.
For more information, refer to the article – r-value and l-value in C

25. What is the difference between call by value and call by reference?

Call by value Call by Reference
Values of the variable are passed while function calls. The address of a variable(location of variable) is passed while the function call.
Dummy variables copy the value of each variable in the function call. Dummy variables copy the address of actual variables.
Changes made to dummy variables in the called function have no effect on actual variables in the calling function. We can manipulate the actual variables using addresses.
A simple technique is used to pass the values of variables. The address values of variables must be stored in pointer variables.
For more information, refer to the article – Call by Value and Call by Reference

26. What is the sleep() function?

sleep() function in C allows the users to wait for a current thread for a given amount of time. sleep() function will sleep the present executable for the given amount of time by the thread but other operations of the CPU will function properly. sleep() function returns 0 if the requested time has elapsed.

For more information, refer to the article – sleep() Function in C

27. What are enumerations?

In C, enumerations (or enums) are user-defined data types. Enumerations allow integral constants to be named, which makes a program easier to read and maintain. For example, the days of the week can be defined as an enumeration and can be used anywhere in the program.

 enum enumeration_name{constant1, constant2, ... }
// An example program to demonstrate working
// of enum in C
#include <stdio.h>

enum week { Mon, Tue, Wed, Thur, Fri, Sat, Sun };

int main()
{
    enum week day;
    day = Wed;
    printf("%d", day);
    return 0;
}
 

Output
2

In the above example, we declared “day” as the variable, and the value of “Wed” is allocated to day, which is 2. So as a result, 2 is printed.

For more information, refer to the article – Enumeration (or enum) in C

28: What is a volatile keyword?

Volatile keyword is used to prevent the compiler from optimization because their values can’t be changed by code that is outside the scope of current code at any time. The System always reads the current value of a volatile object from the memory location rather than keeping its value in a temporary register at the point it is requested, even if previous instruction is asked for the value from the same object. 

29. Write a C program to print the Fibonacci series using recursion and without using recursion.

Fibonacci NumbersFibonacci Numbers
 
// C program to print Fibonacci Series
// with recursion and without recursion
#include <stdio.h>

// Recursive Function to print
// Fibonacci Series
void Fibonacci(int num, int first, int second, int third)
{
    if (num > 0) {
        third = first + second;
        first = second;
        second = third;

        printf("%d ", third);

        // Recursive call for it's
        // n-1 value
        Fibonacci(num - 1, first, second, third)
    }
}

// Driver code
int main()
{
    int num;

    printf("Please Enter number of Elements: ");
    scanf("%d", &num);

    printf(
        "Fibonacci Series with the help of Recursion:\n");

    printf("%d %d ", 0, 1);

    // we are passing n-2 because we have
    // already printed 2 numbers i.e, 0 and 1

    Fibonacci(num - 2, 0, 1, 0);

    printf("\nFibonacci Series without Using Recursion:\n");

    int first = 0, second = 1, third = 0;

    printf("%d %d ", 0, 1);

    // Loop will start from 2 because we have
    // already printed 0 and 1
    for (int i = 2; i < num; i++) {
        third = first + second;

        printf("%d ", third);

        first = second;
        second = third;
    }

    return 0;
}
 


Output:
 Please Enter number of Elements: 5
Fibonacci Series with the help of Recursion:
0 1 1 2 3 
Fibonacci Series without Using Recursion:
0 1 1 2 3 
 
For more information, refer to the article – Fibonacci Numbers

30. Write a C program to check whether a number is prime or not.

Number Prime or notNumber Prime or not
 
// C program to check if a
// number is prime
#include <math.h>
#include <stdio.h>

// Driver code
int main()
{
    int num;
    int check = 1;

    printf("Enter a number: \n");
    scanf("%d", &num);

    // Iterating from 2 to sqrt(num)
    for (int i = 2; i <= sqrt(num); i++) {
        // If the given number is divisible by
        // any number between 2 and n/2 then
        // the given number is not a prime number
        if (num % i == 0) {
            check = 0;
            break;
        }
    }

    if (num <= 1) {
        check = 0;
    }

    if (check == 1) {
        printf("%d is a prime number", num);
    }
    else {
        printf("%d is not a prime number", num);
    }

    return 0;
}

For more information, refer to the article – Prime or Not

Author

Zero Space

About admin

You should write because you love the shape of stories and sentences and the creation of different words on a page.

View All Posts (25)

0 Comments

Author image

You must be to post a comment.