Top 75 C Programming Viva Questions and Answers

C is a procedural programming language initially developed by Dennis Ritchie at Bell Laboratories in 1972. The syntax of many programming languages including Java, PHP, and JavaScript is primarily based on the C language.

Here are the most important C programming Viva questions and answers. The questions are divided into three sections; basic, intermediate, and advanced.

Beginner C Programming Viva Questions and Answers

#1. What is C?

C is a high-level, general-purpose, procedural programming language.

#2. Who developed C language?

Dennis Ritchie.

#3. When was C language developed?

C language was developed in 1970 at Bell Laboratories.

#4. What is a C token?

The smallest individual units in C are known as C tokens. There are six types of tokens in C,

  • Keywords
  • Constants
  • Identifiers
  • Strings
  • Operators
  • Special symbols.

#5. What is a C keyword?

Predefined reserved words with fixed meanings are called keywords. Keywords are the building blocks for program statements.

#6. How many reserved keywords are there in C?

There are 32 reserved keywords in C. They are


#7. What is an identifier in C?

The names of variables, functions, and arrays are referred to as identifiers. These are user-defined names consisting of a sequence of letters and digits. Identifiers must be unique.

#8. What is a variable?

variable is a user-defined name given to memory locations that can be used to store data. A variable may take different values at different times during the execution of a program.

#9. What do you mean by the scope of a variable?

The part of the code where a declared variable can be accessed directly is called the scope of the variable.

#10. What is a constant?

Fixed values that do not change throughout program execution are called constants.

#11. What is meant by variable initialization?

Assigning a value to a variable once declared is called the initialization of a variable.

#12. What are the data types present in C?

C supports five primary (fundamental) datatypes namely integer(int), character(char), floating-point(float), double-precision floating-point(double) and void(void).

Derived types are data types that are derived from fundamental data types. Arrays, pointers, function types, structures, and so on are examples.

User-defined datatypes – structures, unions, enum.

#13. What is an operator?

An operator is a symbol that instructs a computer to perform certain operations. Operators are typically used as part of mathematical or logical expressions. 

#14. What are the operators available in C?

Aritmetic Operators+   –    *    /   %
Relational Operators<    <=    >    >=    ==    !=
Logical Operators&&    ||    !
Assignment Operator+=    -=    *=    /=    %=
Increment and Decrement Operator++    —
Bitwise Operator&    |    ^    `    <<    >>
Conditional Operator?:
Special Operatorsizeof    .    ->

#15. What is operator precedence?

The order in which C evaluates expressions is called operator precedence.

#16. What is the modulus(%) operator?

The modulo division (%) operator produces the remainder of an integer division.

#17. What is the difference between integer arithmetic, real arithmetic, and mixed-mode arithmetic?

When the operands in a single arithmetic expression are both integers, then the operation is known as integer arithmetic. Integer arithmetic always produces an integer value as output. All the examples in the above table are integer arithmetic. For example: 12 / 10 = 1

Real arithmetic refers to arithmetic operations that will use only real operands. The operator % cannot be used with real operands. For example: 3.0 / 2.0 = 1.5

Mixed-mode arithmetic expressions are those in which one of the operands is real and the other is an integer. Since one of the operands is of real type, then the result is always a real number. For example: 12 / 10.0 = 1.2

#18. What is the difference between = and == operator in C?

== is the comparison operator used to check whether the value or expression on the

#19. What is the use of printf() and scanf() functions in C?

The scanf() function is used to input data through the keyboard. It is a general input function available in C. The printf() function can be used to display values of variables and results of expressions on the screen.

#20. What are the different forms of if statements that can be implemented in C?

  • Simple if statement.
  • if….else statement.
  • Nested if….else statement.
  • else if ladder.

#21. What is looping?

The process of executing a sequence of statements repeatedly until some conditions for termination of the loop is satisfied is called looping.

#22. What are the loop control statements provided in C?

  • The while statement.
  • The do statement.
  • The for statement.

#23. What is the use of the break statement?

The break statement can be used to accomplish an early exit from a loop. When a break statement is encountered inside a loop, the loop is immediately exited and the program continues with the statement immediately following the loop.

#24. What is the use of the continue statement?

The continue statement is used to skip a part of a loop. It causes the loop to be continued with the next iteration after skipping any statements in between.

#25. What is an array?

An Array is a collection of variables of a similar type that are referenced by a common name. There are three types of arrays, namely,

  • One Dimensional Array
  • Two Dimensional Array
  • Multi DImensional Array

Intermediate C Programming Viva Questions and Answers

#26. Define String?

A sequence of characters that are treated as a single data item is called a string.

#27. What is the important string handling functions in C?

  • strcpy() – String assignment function.
  • strlen() – Returns the number of characters in the string.
  • strcmp() – Compares two strings.
  • strcat() – Concatenate two strings.
  • strstr() – Used to locate substring.

#28. What is a function?

A block of program code that performs a particular task is called a function.

#29. What is the difference between library functions and user-defined functions?

The functions that are already defined in the C library are called library functions(Built-in functions). They are stored in different header files and these functions cannot be modified by the user. To use a library function in a program, the user has to include the corresponding header file in the program. Some of the library functions in C include printf(), scanf(), getch(), sqrt(), etc.

The function that has to be defined by the user at the time of writing a program is called user-defined functions.

#30. What is the difference between a formal parameter and an actual parameter?

The parameters used in function definitions are called formal parameters and those used in function calls are called actual parameters. The formal parameters list declares the variables that will receive the data sent by the calling program.

c programming viva questions actual and formal parameter diagram

#31. What is recursion?

A technique where a function calls itself is known as recursion.

#32. Distinguish between automatic and static variables.

All local variables that are declared inside a function are known as auto variables unless not specified. That is, by default a local variable is an auto variable. An auto variable is created each time when the function is called and destroyed when the program’s execution leaves the function.

A static variable is similar to an automatic variable. A static variable is declared once and only destroys when the execution of the program finishes.

Automatic VariablesStatic Variables
All local variables are automatic by default. Using the keyword auto is optional.static keyword must be used to declare a static varibale.
The scope of an automatic variable is always local to the function in which it is declared.The scope of an static variable is always local to the function.
Automatic variables are created when the function is called.A static variable is only initialized once, when the program is compiled.
Automatic variables are destroyed when the execution of the function is completed.The value of a static variable persists until the end of the program.

#33. What do you mean by scope, visibility, and lifetime of a variable?

The region of a program in which a variable is available for use is called the scope of the variable.

The ability of a program to access a variable from the memory is the visibility of a variable.

The duration of time in which a variable exists in the memory during execution is the lifetime of a variable.

#34. How does a structure differ from an array?

An array is a collection of data elements of the same type. Structures can have elements of different types.

An array is a derived data type whereas a structure is a user-defined data type.

An array can be used as a built-in datatype. All we have to do is declare and use the array. But in the case of a structure, we have to design and declare it as a data structure before the structure variables are declared and used.

#35. Distinguish between a structure and union.

Both structure and union are user-defined data types in C. The major difference between a structure and a union is in terms of storage. In structures, each member has its own storage location, but all the members of a union share the same location. That is a union can handle only one member at a time.

#36. What are the size of a structure and a union?

The total size of the structure is the sum of the size of every data member. The total size of a union is the size of the largest data member.

#37. What is meant by nested structures and arrays of structures?

The individual members of a structure can be other structures as well, such structure is called a nested structure. That is, a structure may contain another structure as its member.

It is possible to declare an array of structures. The array will have individual structures as its elements.

#38. What is a pointer?

Pointers are a special type of variable that is used to store the address of another variable as their values.

#39. What is type conversion?

The process of converting a variable of one data type into another is referred to as typecasting. Casting allows you to make this type of conversion explicit, or to force it when it wouldn’t normally happen.

#40. What is the difference between a void pointer and a null pointer?

A pointer that holds a null value is called a null pointer. When a pointer has a null value it is not pointing anywhere. A void pointer is a type of pointer that points to some data location in storage, which doesn’t have any specific type.

That is null pointer is a value, while the void pointer is a type.

#41. How does an append mode differ from a write mode in file management?

When the mode is ‘write’, a file is created if the file does not exist. If that file already exists, then the contents are deleted before starting writing.

When the mode is ‘append’, the file is opened with current contents safe. If the file does not exist, then a file with the specified name is created.

#42. What is the significance of EOF in files?

‘EOF’ is a specific designation for a file marker that indicates the end of the data.

#43. What is dynamic memory allocation?

The process of allocating memory at runtime is known as dynamic memory allocation.

#44. What is the difference between a macro and a function in C?

All the macros will be processed before the program compiles.Functions are not preprocessed but compiled.
Macros do not check for compilation errors which leads to unexpected output.Function checks for compilation errors.
Before Compilation, the macro name is replaced by macro value.During function call, transfer of control takes place.
Faster in execution.A bit slower in execution than Macros.

#45. What is a double pointer?

When a pointer holds the address of another pointer then such type of pointer is known as double pointer.

Advanced C Programming Viva Questions and Answers

#46. What are the two ways of passing parameters to functions?

  • Pass by Value – The values of actual parameters are copied to the variables in the parameter list of the called function. Any changes to the parameter in the called function have no effect on data in the calling function. That is the called function works on the copy and not on the original values.
  • Pass by Reference – The memory addresses of the variable rather than the copies of values are sent to the called function. Thus any changes made to the parameter are also made to the original variable.

#47. What are the rules for initializing structures?

The rules to keep in mind while initializing structure variables are,

  • We cannot initialize individual data members inside the structure definition.
  • The order of values enclosed in braces must match the order of members in the structure definition.
  • It is permitted to initialize only the first few members and leave the remaining blank. The uninitialized members should be at the end of the list.
  • The uninitialized members will have default values based on the data type.

#48. What is conditional compilation?

Conditional compilation is a feature of the C preprocessor which can be used to switch on or off a particular line or group of lines in a program. The compiler control directives used for this are,

  • #if
  • #else
  • #elif
  • #endif
  • #ifdef
  • #ifndef
  • #undef
  • #pragma
  • #error

#49. What is the difference between functions and parameterized macros?

All the macros will be processed before the program compiles.Functions are not preprocessed but compiled.
Macros do not check for compilation errors which leads to unexpected output.Function checks for compilation errors.
Before Compilation, the macro name is replaced by macro value.During function call, transfer of control takes place.
Faster in execution.A bit slower in execution than Macros.

#50. What are the typical applications of pointers in developing programs?

  • 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.

#51. What are near, far, and huge pointers?

Near pointer is used to store 16-bit addresses means within the current segment on a 16-bit machine. The limitation is that we can only access 64kb of data at a time.
A far pointer is typically 32-bit, which includes a segment selector, making it possible to point the addresses outside of the default segment.
The huge pointer is also 32-bit and can access outside segments. In far pointer, the segment part cannot be modified, but in Huge it can be.

#52. What is a dangling pointer in C?

A pointer pointing to a non-existing memory location is called a dangling pointer. A dangling pointer is a pointer that has a value that refers to some memory location that is not valid or does not exists.

#53. What is a wild pointer in C?

A pointer in C that is not initialized either by the compiler or programmer is known as a wild pointer. Uninitialized pointers behavior is totally undefined because it may point to some arbitrary location that can be a cause of the program crash.

#54. What is the difference between malloc() and calloc()?

malloc() allocates the requested size of bytes and returns a pointer to the first byte of the allocated space.

calloc() allocates space for an array of elements, initializes them to zero, and then returns a pointer to the memory.

#55. What do you mean by Memory Leak?

A memory leak occurs when memory is allocated but not released back to the operating system. Memory leakage increases unwanted memory usage.

#56. What are command line arguments?

Command line arguments are simply arguments that are specified after the name of the program in the system’s command line, and these argument values are passed on to your program during program execution.

Notify of
Inline Feedbacks
View all comments