Fill your College Details

Summarise With AI
ChatGPT
Perplexity
Claude
Gemini
Grok
ChatGPT
Perplexity
Claude
Gemini
Grok
Back

Top 45 C Programming Viva Questions & Answers

07 Nov 2025
6 min read

Key Takeaways From the Blog

  • Learn the most commonly asked C programming viva questions in 2025 with practical explanations.
  • Strengthen your conceptual understanding of data types, loops, functions, and pointers.
  • Understand how to answer confidently in technical viva rounds using real-world logic.
  • Access sample answers and memory tricks to effectively explain core C concepts.
  • Develop the clarity and confidence necessary to excel in campus interviews and technical interviews.

Introduction

C is a highly used programming language known for its efficiency and flexibility. It is a high-level, general-purpose language that follows a structured approach and is ideal for developing operating systems, language compilers, network drivers, and databases. Many top tech companies prefer candidates with strong C programming skills. If you're preparing for technical interviews, understanding essential concepts and practising C programming viva questions can boost your confidence and improve your chances of success.

Overview of the C language

If you are preparing for the C programming viva questions, then you have to understand fundamentals. C is a powerful general-purpose programming language that provides the foundation for many modern languages like C++, Java, and Python. It is widely used for system programming, embedded systems, operating systems, and application development due to its speed and efficiency.

Founder of the C Language

The C language was developed by Dennis Ritchie at Bell Labs in the early 1970s. He designed it as an improvement over the B language to help in building the UNIX operating system.

When Was the C Language Developed?

C was created in 1972. It was initially developed to rewrite the UNIX operating system, making it more portable and flexible across different machines.

Why is C Called a Mother Language?

C is frequently called the "mother of all programming languages" for the following reasons:

  • Most modern languages borrow their core concepts like loops, functions, and operators.
  • It serves as a base for understanding low-level memory operations and hardware interactions.
  • Operating systems, drivers, and compilers are often written in C, showcasing its foundational nature.

Key Features of the C Language

Understanding the features is very essential to gain a good knowledge to answer the C programming viva questions.Β 

  • Simplicity: Easy to learn and use, with a clean and structured syntax.
  • Speed: Executes programs quickly due to close-to-hardware operations.
  • Portability: Code written in C can run on different machines with minimal changes.
  • Rich Library: Offers a variety of built-in functions to simplify programming.
  • Modularity: Supports functions and reusable code blocks.
  • Low-Level Access: Provides the ability to work directly with memory using pointers.

🎯 Calculate your GPA instantly β€” No formulas needed!!

Essential Topics in the C Language

Anβ€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œ essential subject matter in the C language is the inclusion of data types and control structures, i.e if-else and loops. Other features such as functions, arrays, pointers, memory management, and file handling are also part of the essentials. It is also necessary to learn how to program with structures, preprocessor directives, and dynamic memory allocation. The C programming viva which include these topics serves as the base for further advanced programming β€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œdevelopment.

Structures and Unions in C

C allows the creation of user-defined data types to group related data under a single name. The most common user-defined data types are structures and unions.

i) Structures

A structure is a collection of variables (called structure members) that can be of different data types. Structures help represent records or group dissimilar values.

Example: struct Student { int roll_no; char name[50]; // array elements for the name float marks; };

Accessing Structure Members

To access individual members of a structure, use the dot operator (.) if you have a structure variable, or the arrow operator (->) if you have a pointer to a structure.

Example: struct Student s1; s1.roll_no = 101; // Using dot operator strcpy(s1.name, "Alice"); s1.marks = 88.5;

struct Student *ptr = &s1; printf("%d", ptr->roll_no); // Using arrow operator with a pointer

Nested Structure

A nested structure is a structure that contains another structure as a member.

Example: struct Date { int day, month, year; };

struct Employee { int id; struct Date joining_date; // Nested structure };

ii) Unions

A union is similar to a structure, but it can store only one member value at a time, as all members share the exact memory location. Unions are helpful when variables are mutually exclusive.

Example: union Data { int intValue; float floatValue; char charValue; };

Differences Between Structures, Unions, and Arrays

  • Aβ€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œ normal variable, for instance int x;, is capable of holding only one value at a time.
  • An array is capable of storing multiple values of the same type of data, which can be accessed by indices.
  • Arrays are stored in consecutive memory locations, which makes the accessing and changing of data very β€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œefficient.

Preprocessor Directives in C

Preprocessor directives are instructions that are processed before the actual compilation of the code begins. They help manage code organization, configuration, and conditional code inclusion.

i) File Inclusion

The file inclusion directive is used to include the contents of one file into another, typically to use functions or definitions from header files.

Example:
#include // Includes the Standard Input Output header

ii) Macros

Macros are fragments of code defined using the #define directive. They are replaced by their values or code blocks during preprocessing, allowing for code reuse and easier maintenance.

Example:
#define PI 3.14
#define SQUARE(x) ((x) * (x))

iii) Conditional Compilation

Conditional compilation enables the compilation or exclusion of specific code sections based on predefined conditions. This is useful for platform-specific code or debugging.

Example:
#ifdef DEBUG printf("Debug mode is ON\n"); #endif

Key Takeaways so far

  • Structures group multiple data types under one name.
  • Unions share memory among all members to save space.
  • Dot (.) and Arrow (->) operators are used to access structure members.

Input and Output Functions in C

Input and output (I/O) functions are essential for interacting with users and handling data in C programs. The most common I/O functions are printf and scanf, which utilise various format specifiers to process different data types.

i) printf

The printf function is used to display output on the screen. It supports multiple format specifiers to print different data types:

  • %d: Prints an integer
  • %f: Prints a floating-point number
  • %c: Prints a single character
  • %s: Prints a string

Example: int age = 25; printf("Age: %d\n", age);

ii) scanf

The scanf function is used to take keyboard input from the user. It also uses format specifiers to read various data types.

Example: float price; scanf("%f", &price);

Common Format Specifiers

  • %d: Integer values
  • %f: Floating-point numbers
  • %c: Single characters
  • %s: Strings

Additional Input/Output Functions

  • clrscr: Clears the screen (commonly used in some compilers, but not part of the standard C library).
  • gotoxy: Moves the cursor to a specified position on the screen (also compiler-specific).
  • String handling functions: Functions like gets, puts, strcpy, and strlen are used for string input, output, and manipulation.
  • File handling functions: Functions such as fprintf, fscanf, fgets, and fputs are used for input and output operations with files.

Key Takeaways so far

  • printf() is used for formatted output, scanf() for input.
  • Use proper format specifiers for each data type.
  • String and file-handling functions extend C’s I/O capabilities.

Operators and Expressions in C

Operators are special symbols or keywords that perform operations on variables and values. In C, operators are fundamental for forming expressions and manipulating data.

i) Arithmetic Operators

Arithmetic operators are used for mathematical calculations:

  • + (addition)
  • - (subtraction)
  • * (multiplication)
  • / (division)
  • Modulus operator % (remainder after division)

Example:
int result = 10 % 3; // result is 1

ii) Assignment Operators

Assignment operators assign values to variables:

  • = (simple assignment)
  • +=, -=, *=, /=, %= (compound assignments)

Example:
x += 5; // equivalent to x = x + 5

iii) Relational Operators

Relational operators compare two values:

  • == (equal to)
  • != (not equal to)
  • > (greater than)
  • < (less than)
  • >= (greater than or equal to)
  • <= (less than or equal to)

iv) Logical Operators

Logical operators are used to combine or invert conditions:

  • && (logical AND)
  • || (logical OR)
  • ! (logical NOT)

v) Increment and Decrement Operators

These operators increase or decrease a variable’s value by one:

  • ++ (increment operator)
  • -- (decrement operator)

Example:
i++; // increases i by 1

vi) Unary Operator

A unary operator operates on a single operand. Examples include:

  • Unary plus (+)
  • Unary minus (-)
  • Increment (++)
  • Decrement (--)
  • Address-of (&)
  • Value-at (*)
  • One's complement operator ~ (bitwise NOT)
  • sizeof operator (returns the size of a data type or variable in bytes)

Example:
int size = sizeof(int); // returns size of int

vii) Bitwise Operators

Bitwise operators perform operations at the bit level:

  • & (AND)
  • | (OR)
  • ^ (XOR)
  • ~ (NOT, or ones complement operator)
  • << (left shift)
  • >> (right shift)

viii) Conditional Operator

The conditional operator (ternary operator) ?: is a shorthand for if-else statements.

Example:
int max = (a > b) ? a : b;

ix) Special Operators

Special operators include:

  • , (comma operator)
  • -> (structure pointer operator)
  • . (structure member operator)
  • sizeof (already discussed above)

Arrays and Strings in C

Arrays are a fundamental data structure in C that allow you to store multiple values of the same data type in contiguous memory locations. This means that all elements of the array are stored consecutively in memory, making it efficient to access and manipulate extensive collections of data.

Definition of an Array

An array is a collection of elements, all of the same data type, stored under a single variable name. Each component of the array can be accessed using its index.

Syntax: data_type array_name[size];

Example: int numbers[5]; // Declares an array of 5 integers

Initialization of Arrays

Arrays can be initialized at the time of declaration using an initializerβ€”a comma-separated list of constant expressions enclosed in braces.

Example: int numbers[5] = {1, 2, 3, 4, 5};

If not all elements are initialized, the remaining elements are set to zero (for static and global arrays).

Types of Arrays

C supports several types of arrays:

  • One-dimensional arrays: These are used to store a list of values in a single row. Example: int arr[10];
  • Two-dimensional arrays: These are used for tables or matrices. Example: int matrix[3][4];
  • Multi-dimensional arrays: These are arrays that have more than two dimensions, are very rarely used but are still β€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œsupported.

Character Arrays (Strings)

A character array is an array of type char, often used to store strings. In C, a string is a sequence of characters terminated by a null character ('\0').

Example: char name[10] = "Alice";

Here, 'A', 'l', 'i, 'c', 'e', and the null character are stored in contiguous memory locations.

Differences Between Arrays and Regular Variables

  • A regular variable (e.g., int x;) can store only a single value at a time.
  • An array can store multiple values of the same data type, accessible via indices.
  • Arrays occupy contiguous memory locations, which allows efficient data access and manipulation.

File Handling in C

File handling in C enables programs to read from and write to files, allowing for the permanent storage and retrieval of data. Understanding file operations is essential for managing data beyond the program’s runtime.

Types of Files

C supports two main types of files:

  • Text files: Store data as readable characters. These files can be opened and edited using any text editor.
  • Binary files: Store data in binary format, which is not human-readable but is more efficient for storing large amounts of data.

File Opening Modes

When working with files, you must specify a file opening mode to determine how the file will be accessed. Common modes include:

  • "r": Open an existing file for reading.
  • "w": Create a new file for writing (or overwrite if it exists).
  • "a": Open a file for appending data at the end.
  • "r+": Open an existing file for both reading and writing.
  • "w+": Create a new file for both reading and writing.
  • "a+": Open a file for both reading and appending.
  • "rb", "wb", "ab": Same as above, but for binary files.

Standard File-Handling Functions

C provides several standard file-handling functions in the stdio.h library:

  • fopen(): Opens a file with a specified mode.
  • fclose(): Closes an open file.
  • fprintf(), fscanf(): Write to and read from files using formatted input/output.
  • fgetc(), fputc(): Read and write a single character.
  • fgets(), fputs(): Read and write strings.
  • fread(), fwrite(): Read and write blocks of data (mainly used with binary files).
  • fseek(), ftell(): Move the file pointer and determine its position.

Control Structures in C

Control structures are fundamental in C programming, as they determine the flow of execution within a program. They are essential for making decisions, repeating tasks, and efficiently managing data structures such as arrays.

If Statements

Suppose statements are used to execute a block of code only if a specific condition is proper. They are the primary decision-making statements in C.

Example: if (score > 60) { printf("You passed!\n"); }

You can use if-else and else if for handling multiple conditions.

Loops and Loop Control Statements

Loops are used to perform repetitive tasks, often when working with array elements or processing items in other data structures.

  • for loop: Ideal when the number of iterations is known, commonly used for traversing arrays. for (int i = 0; i < 5; i++) { printf("%d ", numbers[i]); // Accessing array elements }
  • while loop: Used when the number of iterations is not known in advance.
  • do-while loop: Ensures the loop body executes at least once.

Loop Control Statements

C provides specific loop control statements:

  • break: Exits the loop immediately, skipping any remaining iterations.
  • continue: Skips the current iteration and proceeds to the next.
  • goto: Transfers control unconditionally to a labeled statement elsewhere in the program (use with caution for code clarity).

Example: for (int i = 0; i < 10; i++) { if (i == 5) continue; // Skips printing 5 printf("%d ", i); }

Working with Data Structures

Control structures are frequently used to process and manipulate data structures, such as arrays, linked lists, and others. For example, loops are essential for iterating over array elements to perform calculations or data transformations.

Functions in C

Functionsβ€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œ are groups of instructions that are aimed at executing certain tasks, programs thus becoming modular, reusable, and easier to maintain. In C, functions may be built-in functions (offered by standard libraries) or user-defined functions (made by the β€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œprogrammer).

Built-in Functions

Built-in functions are pre-defined in C libraries. Examples include printf() for output, scanf() for input, strlen() for string length, and sqrt() for square root. These functions simplify everyday programming tasks and are available by including the appropriate header files (such as stdio.h or math.h).

User-Defined Function

The programmer writes a user-defined function to perform a particular operation. These functions help break down complex problems into smaller, manageable parts.

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

Parameter Passing: Actual and Formal Parameters

When calling a function, values are passed to it using parameters:

  • Actual parameters are the real values or variables supplied in the function call.
  • Formal parameters are the variables defined in the function’s declaration and used within the function body.

Example: void greet(char name[]) { // name is the formal parameter printf("Hello, %s!", name); } // Function call: greet("Alice"); // "Alice" is the actual parameter

Recursion

Recursion is a technique where a function calls itself to solve a problem. Recursive functions must have a base case to terminate the process and avoid infinite loops.

Example: int factorial(int n) { if (n == 0) return 1; else return n * factorial(n - 1); }

Key Takeaways so far

  • Functions improve code reusability and clarity.
  • Recursion simplifies repetitive problems like factorials.
  • Formal vs. actual parameters distinguish declarations from calls.

Pointers in C

Pointers are a unique feature of C that provide powerful capabilities for managing memory space and optimizing performance. A pointer is a variable that stores the memory address of another variable, enabling direct access and manipulation of data in memory.

Pointer Variable

A pointer variable is declared using the asterisk (*) symbol. It can store the memory address of a specific data type.

Example: int x = 10; int *ptr = &x; // ptr stores the memory address of x

Identifiers and Memory Address

The name of the pointer (like ptr above) is an identifier. The value stored in a pointer is always a memory address, allowing you to reference and manipulate the data stored elsewhere in memory.

Pointer Functions

Pointer functions are functions that either receive pointers as arguments or return pointers. This enables efficient data manipulation, particularly with arrays and large data structures.

Example: void updateValue(int num) { num = 20; } // Usage: int value = 5; updateValue(&value); // value is now 20

Dangling Pointer Variable

A dangling pointer variable occurs when a pointer still holds the memory address of a variable that has been deallocated or is no longer in scope. Accessing a dangling pointer can lead to unpredictable behaviour or program crashes.

Example: int *p; { int temp = 100; p = &temp; } // temp goes out of scope here; p becomes a dangling pointer

Memory Space and Performance

By using pointers, a program can quickly and efficiently perform specific tasks without requiring extra memory, as the address of the memory space is provided directly. Pointers are thus indispensable for the three core areas of dynamic memory allocation, arrays, and algorithm techniques that require low-level memory manipulation to execute code more efficiently.Β 

Data Types and Variables in C

Knowledge about data types and variables is the base layer of the programming language C. Data types define the nature of the data that a variable is capable of holding. In contrast, variables are the names of the storage places where the values are β€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œkept.Β 

Basic (Primary or Fundamental) Data Types

C provides several basic data types (also known as primary or fundamental data types or primitive data types):

  • int: Used for integer values (e.g., 5, -12).
  • char: Used for single characters (e.g., 'A', 'z').
  • float: Used for floating-point numbers (e.g., 3.14, -0.001).

Derived Data Types

Derived datatypes are built from basic data types. Common examples include:

  • Pointers: Variables that store the memory address of another variable.
  • Arrays: Collections of elements of the same data type.
  • Structures: Groupings of variables of different data types under a single name.

User-Defined Data Types

C allows programmers to define their own data types, known as user-defined data types, to organize better and manage complex data. Examples include:

  • structures (using struct)
  • unions
  • enumerations (using enum)
  • typedef for creating type aliases

Declaration and Initialization of Variables

Variables must be declared with a specific data type before use. Initialization assigns an initial value to a variable at the time of declaration.

Example: int count = 10; char letter = 'A'; float price = 5.99;

Variable’s Scope

A variable’s scope refers to the region of the program where the variable is accessible. Variables declared inside a function are local to that function, while those declared outside are global.

Static Variables

A static variable preserves its value between function calls and limits its scope to the file or function in which it is declared.

Example: void demo() { static int count = 0; // retains value between calls count++; printf("%d", count); }

Key Takeaways so far

  • Data types define what kind of data a variable can hold.
  • Static variables retain values between function calls.
  • Scope determines variable accessibility.

Basic Level C Programming Viva Questions for Freshers

Below are a few of the most asked basic viva questions for C programming, which help you understand the fundamentals.

1. What is the C language?
Early in the 1970s, Dennis Ritchie developed the general-purpose computer language C. Because of its effectiveness, portability, and strong connection to hardware, it is frequently utilized in embedded systems, operating systems, and system programming.

2. What are the key features of C?

  • Low-level memory access
  • Fast performance
  • Rich library support
  • Structured programming
  • Portability
  • Simple syntax

3. How is a C variable definition different from a declaration?

  • Declaration tells the compiler about a variable’s type and name, but memory is not allocated.
  • Definition declares and also allocates memory for the variable.

4. What does the printf() function in C language do?
printf() is used to display output on the screen. It allows formatted output using format specifiers like %d, %f, %s, etc.

5. What is the purpose of the C function scanf()?
scanf() is used to take input from the user during program execution. It uses the conventional keyboard input to read structured data.

6. What makes float in C different from int in C?
int is used to store whole numbers (e.g., 5, -3) while float stores numbers with decimal points (e.g., 3.14, -2.75).

7. What is the role of a pointer in accessing memory in C?
Pointerβ€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œ is a key concept through which memory in C language is accessed. Basically, a pointer stores the location of another variable. With the help of this memory address, the pointer gives you the ability to get or set the value that is saved there. Mainly, it finds its usage in situations such as the implementation of arrays, the use of dynamic memory, or the passing the data to functions in a more efficient β€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œway.

8. What exactly is the main() function in C used for?
Every C program begins with the main() function. A C program starts running after this function.

9. What is a constant in C?
A fixed value that cannot be modified while a program is running is called a constant. It is declared using the const keyword or #define.

10. What are keywords in C?
Keywords are reserved words with predefined meanings in C (e.g., int, return, if, while). They cannot be used as variable names.

11. What is a data type in C?
A data type defines the type of data a variable can hold, such as int for integers, char for characters, float for decimals, etc.

12. What are the different types of loops in C?
C supports:

  • for loop
  • while loop
  • do-while loop

13. What is the purpose of the return statement in C?
To leave a function and also return a value to the caller function, use return.

14. What is the difference between = and == in C?
= is the assignment operator, used to assign values.
== is the equality operator, used to compare two values.

15. What is the syntax of the C for loop?

for(initialization; condition; update) {
   // loop body
}

Intermediate Level C Programming Viva Questions

These C viva questions will test your understanding of control structures, functions, arrays, and pointers, helping you prepare for real-time programming scenarios.

1. How does call by reference differ from call by value in C?

  • Call by value: A copy of the actual value is passed to the function. Changes made inside the function don’t affect the original value.
  • Call by reference: The address of the variable is passed, so any changes inside the function reflect in the original variable.

2. What is recursion in C?
Recursion in programming refers to a technique where a function repeatedly calls itself, breaking down a complex problem into simpler sub-problems, until it reaches a condition that stops further calls (known as the base case).

3. What are storage classes in C?
Storage classes in C determine the scope, duration, and accessibility of variables within a program. Common storage classes in C include:

  • auto
  • register
  • static
  • extern

4. How do malloc() and calloc() differ in terms of memory allocation in C?

  • malloc(size) allocates uninitialized memory.
  • calloc(n, size) in C is used to allocate memory for n items, and it automatically sets all the values to zero.

5. What is a dangling pointer in C?
A dangling pointer refers to a situation where a pointer still points to a memory location that has already been released or deallocated. Accessing such a pointer can result in unpredictable or erroneous program behavior.

6. What is a structure in C?
A user-defined data type called a structure combines linked variables, possibly of multiple data types, under a single name. It helps to organize complex data.

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

7. Why is typedef used in C programming?
typedef is used in C to define a new identifier or alias for an existing data type, making the code more readable and easier to manage.

typedef unsigned int uint;

8. What differentiates union in C from structure?

  • Each and every member of a structure has a unique memory location.
  • The memory location is the same for all union members. A value can only ever be stored by one member.

9. What is pointer arithmetic in C?
Adding, subtracting, increasing, and decreasing pointers to move between memory addresses of arrays or variables is made possible via pointer arithmetic.

10. What is a null pointer?
A null pointer is a pointer that points to nothing or zero. It is used to indicate that the pointer is not assigned any valid memory address.

int *ptr = NULL;

11. Why is the sizeof operator in C used?
A variable's or data type's memory usage is indicated by the size of operation.

int x;
printf("%d", sizeof(x));  // Output might be 4

12. What makes "continue" different from "break"?

  • break: Exits the loop or switch immediately.
  • Continue: The continue statement skips the current iteration and jumps to the next loop cycle.

13. What are macros in C?
Code fragments are substituted by macros, which are preprocessor directives written with #define, prior to compilation.

#define PI 3.14

14. What is the function of the static keyword in C?
By utilizing the static keyword, a variable's value is preserved in between function calls. It also limits variable or function scope to the file.

15. Define command-line argument in C
When a program starts, command line arguments are inputs sent from the terminal to the main() method.

int main(int argc, char *argv[])

Advanced Level Viva Questions of C Programming

Explore these important C Programming Viva Questions to strengthen your understanding of advanced concepts.

1. What is dynamic memory allocation in C?
Dynamic memory allocation in C allows the program to allocate memory at runtime using functions like malloc(), calloc(), realloc(), and free(). It provides more flexibility than static memory allocation.

2. What are the differences between C programming's pre-increment and post-increment operators?

Pre-increment (++k) involves increasing the variable k first, and then using the increased value in the expression. Whereas, post-increment (k++) uses the initial value of k in the expression first, followed by the increment.

3. What are the advantages and disadvantages of using goto in C?

Advantages:

  • Helps in skipping straight to a particular section of the code.
  • Useful to break out of deeply nested loops.
  • It can simplify error handling in some cases.

Disadvantages:

  • Makes the code hard to read and understand.
  • Difficult to maintain and debug.
  • Can lead to messy code, known as "spaghetti code."
  • Not recommended in modern programming.

4. What is the difference between strcpy() and strncpy() in C?

  • strcpy() copies a null-terminated string, assuming the destination has enough space, without any bounds checking.
  • strncpy() copies a specified number of characters and ensures that the destination buffer is not overflowed, adding a null terminator if there is room.

5. Describe the concept of bitwise operators in C
Bitwise operators work with numbers that are represented in binary. Common bitwise operators include:

  • & (AND)
  • | (OR)
  • ^ (XOR)
  • ~ (NOT)
  • << (Left shift)
  • >> (Right shift)

6. What is an inline function in C?
An inline function is one where the compiler attempts to insert the code of the function directly into the places where it is called, improving performance by reducing function call overhead.

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

7. What is the difference between struct and enum in C?

  • A struct is a data type that allows grouping of variables of different types under a single name.
  • An enum is a user-defined data type consisting of named integer constants, useful for creating a set of values.

8. In C, what are function pointers used for?
A program may store function addresses and make dynamic calls to them through function pointers. This provides flexibility in function selection at runtime, commonly used in callback mechanisms.

void (*ptr)(int);
ptr = &function_name;

9. What is the volatile keyword used for in C?
Even if a variable looks unused, the volatile keyword instructs the compiler not to optimize it. This is particularly useful for variables that can change unexpectedly, like hardware registers or shared memory in multi-threaded programs.

10. Explain the concept of a memory leak in C.
A memory leak occurs when a program allocates memory dynamically (using malloc(), calloc(), etc.) but fails to release it (using free()). Over time, this causes the program to consume more memory, eventually leading to system resource exhaustion.

11. What is the difference between fopen() and freopen()?

  • fopen() is used to open a file in a specific mode for reading, writing, etc.
  • freopen() is used to reassign an existing file pointer to a new file, allowing redirection of standard input/output streams.

12. What is the significance of the exit() function in C?
The exit() function terminates a program immediately, returning a status code to the operating system. It can be used to exit the program from anywhere, including inside a function.

13. How does a stack overflow occur in C?
A stack overflow happens when the program uses more stack space than is allocated, typically due to excessive recursion or creating too large of local variables. This can cause the program to crash or exhibit undefined behavior.

14. What is a segmentation fault in C?
A segmentation fault occurs when a program tries to access memory that it isn’t allowed to, such as accessing an invalid pointer or a memory location outside the bounds of an array.

15. Explain the concept of multithreading in C.
Multithreading allows a program to perform multiple tasks simultaneously by creating independent threads. Each thread runs in its own execution context, allowing for parallel processing, and is often managed using libraries like pthread.

Conclusion

C programming is a must-have skill for any computer science student. Getting to know the language basics, such as syntax, as well as advanced topics like pointers and file handling, is imperative for any programmer. Instead of cramming answers, go for understanding the concepts. This strategy will not only help you to have a good performance in your C programming oral exam, but also will be the stepping-stones to a career in software β€‹β€β€‹β€Œβ€β€‹β€β€Œβ€‹β€β€‹β€Œβ€β€‹β€β€Œdevelopment.Β 

Why It Matters?

Mastering C programming viva questions builds a strong foundation for advanced programming languages like C++, Java, and Python. It reflects not only your technical skill but also your ability to communicate programming logic effectively β€” a crucial trait for any software developer or engineer.

Practical Advice for Learners

  • Explain your code as if you’re teaching someone. It improves clarity and confidence.
  • Real understanding comes from coding, not just reading theory.
  • Pair up with a friend and test each other using sample questions.
  • Keep learning how C concepts apply in modern embedded systems and AI programming.

Read More Articles

Chat with us
Chat with us
Talk to career expert