C Language Viva & Interview Questions

Basic Concepts (Q1-Q10)

Q1. What is C programming language? Who developed it?

Answer: C is a general-purpose, procedural programming language developed by Dennis Ritchie at Bell Laboratories in 1972. It was designed for system programming and is widely used in operating systems, embedded systems, and application development.

Q2. What are the features of C language?

Answer:

  • Simple and easy to learn
  • Portable across different platforms
  • Rich library functions
  • Fast execution speed
  • Low-level memory access
  • Modular programming support
  • Extensible and flexible

Q3. What is the difference between compiler and interpreter?

Answer: Compiler translates entire program into machine code before execution. Interpreter translates and executes line by line. C uses a compiler.

Q4. What is a token in C?

Answer: Token is the smallest unit of a C program. Types include: keywords, identifiers, constants, strings, operators, and special symbols.

Q5. What are keywords in C?

Answer: Keywords are reserved words with predefined meaning. Examples: int, char, float, if, else, for, while, return, void, struct, etc.

Q6. What is the difference between variable declaration and definition?

Answer: Declaration announces existence and type (e.g., extern int x;). Definition allocates memory and optionally initializes (e.g., int x = 10;).

Q7. What are data types in C? List them.

Answer: Data types specify type of data. Basic types: int, char, float, double, void. Derived types: array, pointer, structure, union, enum.

Q8. What is the difference between signed and unsigned data types?

Answer: Signed types can hold positive and negative values. Unsigned types can hold only non-negative values (zero and positive). Unsigned types have larger positive range.

Q9. What is the size of int in C?

Answer: Size of int depends on compiler and platform. Typically 2 or 4 bytes. Use sizeof(int) to check.

Q10. What are format specifiers? Give examples.

Answer: Format specifiers define data type in I/O operations. Examples: %d (int), %f (float), %c (char), %s (string), %lf (double), %p (pointer).

Operators and Expressions (Q11-Q15)

Q11. Explain operator precedence in C.

Answer: Operators have priority order. Parentheses () have highest precedence. Then: unary, multiplicative (*, /, %), additive (+, -), relational (<, >, ==, !=), logical (&&, ||), assignment (=).

Q12. What is the difference between = and == operators?

Answer: = is assignment operator (assigns value). == is equality comparison operator (compares values). Using = in if condition assigns value (often bug).

Q13. What are bitwise operators? Give examples.

Answer: Bitwise operators work on bits. & (AND), | (OR), ^ (XOR), ~ (NOT), << (left shift), >> (right shift). Example: 5 & 3 = 1.

Q14. Explain increment and decrement operators.

Answer: ++ increments by 1, -- decrements by 1. Pre-increment (++x) increments before use. Post-increment (x++) increments after use.

Q15. What is type casting? Give example.

Answer: Converting one data type to another. Explicit: (float)5 converts int to float. Implicit: automatic conversion by compiler.

Control Statements and Loops (Q16-Q20)

Q16. What is the difference between if-else and switch statement?

Answer: if-else checks boolean conditions. switch checks multiple discrete values. switch is faster for many cases, but if-else is more flexible.

Q17. Explain break and continue statements.

Answer: break exits loop/switch immediately. continue skips remaining statements in current iteration and continues next iteration.

Q18. What is the difference between while and do-while loop?

Answer: while checks condition before execution (may not execute). do-while checks condition after execution (executes at least once).

Q19. What is infinite loop? How to create one?

Answer: Loop that never terminates. Created by: while(1), for(;;), or condition that never becomes false. Use break to exit.

Q20. Explain nested loops with example.

Answer: Loop inside another loop. Used for 2D arrays, patterns. Example: outer loop for rows, inner loop for columns in matrix.

Arrays and Strings (Q21-Q25)

Q21. What is an array? How is it declared?

Answer: Array is collection of similar data elements. Declaration: int arr[10]; (array of 10 integers). Index starts from 0.

Q22. Why array index starts from 0 in C?

Answer: Array name represents base address. arr[i] is calculated as *(arr + i). So arr[0] is *(arr + 0) = base address. This makes pointer arithmetic simple.

Q23. What is a string in C? How is it stored?

Answer: String is array of characters terminated by null character '\\0'. Stored as character array. Example: char str[] = "Hello";

Q24. Explain string functions in C. Give examples.

Answer: strlen() - length, strcpy() - copy, strcat() - concatenate, strcmp() - compare, strstr() - search substring. Include <string.h> header.

Q25. What is 2D array? How to access elements?

Answer: Array of arrays (matrix). Declaration: int matrix[3][3]; Access: matrix[row][col] or *(*(matrix + row) + col).

Functions (Q26-Q30)

Q26. What is a function? What are its advantages?

Answer: Function is block of code performing specific task. Advantages: reusability, modularity, easier debugging, code organization, abstraction.

Q27. What is function prototype? Why is it needed?

Answer: Function declaration before definition. Tells compiler about function name, return type, parameters. Needed when function is called before definition.

Q28. Explain call by value and call by reference.

Answer: Call by value passes copy of variable (original unchanged). Call by reference passes address using pointers (original can be modified).

Q29. What is recursion? Give example.

Answer: Function calling itself. Must have base case to terminate. Example: factorial, fibonacci. Slower than iteration but simpler for some problems.

Q30. What is the difference between function declaration and definition?

Answer: Declaration (prototype) announces function signature. Definition contains actual implementation/code of function.

Pointers (Q31-Q35)

Q31. What is a pointer? How is it declared?

Answer: Pointer stores address of variable. Declaration: int *ptr; (pointer to integer). Use & to get address, * to dereference.

Q32. What is NULL pointer? Why is it used?

Answer: NULL pointer points to nothing (address 0). Used to indicate pointer doesn't point to valid memory. Check for NULL before dereferencing to avoid errors.

Q33. What is pointer arithmetic? Explain.

Answer: Arithmetic operations on pointers. ptr + 1 moves to next element (not next byte). Size depends on data type. Example: int* ptr; ptr++ increments by sizeof(int).

Q34. What is void pointer? How is it used?

Answer: void* can point to any data type. Cannot be dereferenced directly. Must cast to specific type before use. Used in generic programming.

Q35. What is pointer to pointer? Give example.

Answer: Pointer storing address of another pointer. Declaration: int **ptr; Used for dynamic 2D arrays, function parameters modifying pointer.

Memory Related Questions (Q36-Q40)

Q36. Explain dynamic memory allocation in C.

Answer: Allocating memory at runtime. Functions: malloc() - allocates, calloc() - allocates and initializes to 0, realloc() - resizes, free() - deallocates.

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

Answer: malloc() takes size in bytes, returns uninitialized memory. calloc() takes count and size, returns memory initialized to zero. calloc() is safer.

Q38. What is memory leak? How to prevent it?

Answer: Memory leak occurs when allocated memory is not freed. Prevent by: always free() allocated memory, set pointer to NULL after free, match malloc/calloc with free.

Q39. What is dangling pointer? How to avoid it?

Answer: Pointer pointing to freed memory. Avoid by: set pointer to NULL after free(), don't use pointer after freeing, be careful with function returns.

Q40. What is stack and heap memory?

Answer: Stack: automatic memory for local variables, managed by compiler, faster, limited size. Heap: dynamic memory via malloc(), managed by programmer, slower, larger size.

Structures and Unions (Q41-Q45)

Q41. What is a structure? How is it defined?

Answer: Structure groups related data of different types. Definition: struct Student { int roll; char name[50]; float marks; };

Q42. What is the difference between structure and union?

Answer: Structure allocates separate memory for each member (size = sum of members). Union shares memory (size = largest member). Only one union member active at a time.

Q43. How to access structure members?

Answer: Using dot operator: struct_var.member. Using arrow operator with pointer: struct_ptr->member or (*struct_ptr).member.

Q44. What is typedef? Give example.

Answer: Creates alias for data type. Example: typedef struct Student Student; Now use Student s1; instead of struct Student s1;

Q45. Can structure contain functions?

Answer: No, C structures cannot contain functions. They can contain only data members. Use function pointers to achieve similar behavior.

Storage Classes (Q46-Q47)

Q46. What are storage classes in C? List them.

Answer: Storage classes define scope, lifetime, and location of variables. Types: auto (default local), static (retains value), extern (global), register (fast access).

Q47. What is the difference between static and extern?

Answer: static: internal linkage, retains value between function calls, scope limited to file/block. extern: external linkage, declares global variable defined elsewhere.

Compilation Process (Q48-Q50)

Q48. Explain the compilation process in C.

Answer: Four stages:

  1. Preprocessing: Expands macros, includes headers (#include, #define)
  2. Compilation: Converts source code to assembly language
  3. Assembly: Converts assembly to object code (.o files)
  4. Linking: Links object files and libraries to create executable

Q49. What are preprocessor directives? Give examples.

Answer: Instructions processed before compilation. Examples: #include (includes header), #define (defines macro), #ifdef/#endif (conditional compilation), #pragma.

Q50. What is the difference between #include <stdio.h> and #include "stdio.h"?

Answer: <stdio.h> searches in system directories. "stdio.h" searches in current directory first, then system directories. Use <> for system headers, "" for user headers.

💡 Viva Preparation Tip

Practice explaining concepts in your own words. Understand not just what, but why and how. Be ready to write small code snippets. Review compiler errors and how to fix them. Practice explaining with real-world examples.

Question Categories Summary

CategoryQuestionsImportance
Basic ConceptsQ1-Q10: C basics, tokens, data types, variablesHigh
Operators & ControlQ11-Q20: Operators, control statements, loopsHigh
Arrays & FunctionsQ21-Q30: Arrays, strings, functions, recursionVery High
Pointers & MemoryQ31-Q40: Pointers, dynamic memory, stack/heapVery High
Structures & AdvancedQ41-Q50: Structures, unions, storage classes, compilationHigh

Frequently Asked Questions

Q1: How should I prepare for C programming viva?

Understand concepts deeply, not just memorize answers. Practice explaining in your own words. Be ready to write code snippets. Review your lab programs and understand them thoroughly. Practice explaining algorithms and logic. Understand why things work, not just what they do. Prepare examples for each concept.

Q2: What topics are most frequently asked in viva?

Pointers (most common), memory management (malloc/free), arrays and strings, functions (call by value/reference), structures, file handling, and compilation process. Questions about your lab programs are also very common. Be prepared to explain any program you've written, including algorithms and logic.

Q3: How do I answer questions about pointers confidently?

Understand that pointers store addresses. Practice with simple examples. Draw memory diagrams. Explain pointer arithmetic clearly. Understand the relationship between arrays and pointers. Practice explaining with examples: int *ptr = &x;means ptr stores address of x. Be clear about * (dereference) and & (address of) operators.

Q4: What if I don't know the answer to a question?

Be honest - say you're not sure but explain what you do know. Try to reason through the problem. Show your thinking process. It's better to admit uncertainty than to guess incorrectly. If you know a related concept, mention it. Examiners appreciate honesty and logical thinking.

Q5: Should I memorize all these answers?

Don't memorize - understand concepts. Once you understand a concept, you can explain it in your own words. Understanding enables you to answer variations and related questions. Focus on understanding why things work, not just what they are. Practice explaining concepts to others.

Q6: How important is it to know the compilation process?

Very important - it's frequently asked. Understand the four stages: preprocessing (macros, includes), compilation (source to assembly), assembly (assembly to object code), and linking (object files to executable). Know what happens in each stage. This shows deep understanding of how C programs work.

Q7: What's the best way to explain complex concepts?

Start with simple explanation, then add details. Use examples and analogies. Draw diagrams if possible. Break complex concepts into smaller parts. Relate to real-world examples. Show code examples. Explain step-by-step. Practice explaining to friends or family - if you can explain it simply, you understand it well.

Q8: How do I handle questions about my lab programs?

Review all your lab programs before viva. Understand the algorithm, logic, and code. Be able to explain why you used specific approaches. Know alternative solutions. Understand time/space complexity if applicable. Be ready to modify programs or explain how you would improve them. Practice explaining each program clearly.

Conclusion

Viva examinations test not just your knowledge but your understanding and ability to explain concepts. These questions cover fundamental C programming concepts that every programmer should know. Understanding these concepts deeply will help you not just in viva but in your programming career.

Focus on understanding concepts rather than memorizing answers. Practice explaining concepts in your own words. Be confident but honest - it's okay to say you don't know something. The key is to show your understanding and thinking process. Regular practice and thorough preparation will help you perform well in viva examinations.

Related Links

🔹 Author: Dr. J. Siva Ramakrishna

🔹 Institution: Narayana Engineering College, Gudur

🔹 Last Updated: 9 January 2026