C Language Viva Questions & Answers - MSBTE K Scheme
Unit 1: Basics of C Programming
Q1. What is a variable in C?
A1. A variable is a name given to a memory location to store data. Its value can change during program execution.
Q2. Define a constant in C.
A2. A constant is a fixed value that cannot be changed during the execution of a program.
Q3. What is the use of #include<stdio.h>?
A3. It tells the compiler to include the standard input-output library functions before actual compilation.
Q4. What are data types in C?
A4. Data types define the type of data a variable can hold, such as int, float, char, etc.
Q5. What is the main() function?
A5. The main() function is the entry point of any C program.
Q6. What is the syntax of printf()?
A6. printf("format string", variables); is used to display output to the screen.
Q7. What is scanf() used for?
A7. scanf() is used to take input from the user.
Q8. What is the purpose of return 0 in main()?
A8. It indicates the program executed successfully.
Q9. What are keywords in C?
A9. Keywords are reserved words that have special meaning, such as int, return, if.
Q10. How many keywords are there in C?
A10. There are 32 keywords in the C language.
Q11. What is a variable in C? (Example 11)
A11. A variable is a name given to a memory location to store data. Its value can change during program execution.
(Detailed explanation 11)
Q12. Define a constant in C. (Example 12)
A12. A constant is a fixed value that cannot be changed during the execution of a program. (Detailed explanation 12)
Q13. What is the use of #include<stdio.h>? (Example 13)
A13. It tells the compiler to include the standard input-output library functions before actual compilation. (Detailed
explanation 13)
Q14. What are data types in C? (Example 14)
A14. Data types define the type of data a variable can hold, such as int, float, char, etc. (Detailed explanation 14)
Q15. What is the main() function? (Example 15)
A15. The main() function is the entry point of any C program. (Detailed explanation 15)
Q16. What is the syntax of printf()? (Example 16)
A16. printf("format string", variables); is used to display output to the screen. (Detailed explanation 16)
Q17. What is scanf() used for? (Example 17)
A17. scanf() is used to take input from the user. (Detailed explanation 17)
Q18. What is the purpose of return 0 in main()? (Example 18)
A18. It indicates the program executed successfully. (Detailed explanation 18)
Q19. What are keywords in C? (Example 19)
A19. Keywords are reserved words that have special meaning, such as int, return, if. (Detailed explanation 19)
Q20. How many keywords are there in C? (Example 20)
A20. There are 32 keywords in the C language. (Detailed explanation 20)
Q21. What is a variable in C? (Example 21)
A21. A variable is a name given to a memory location to store data. Its value can change during program execution.
(Detailed explanation 21)
Q22. Define a constant in C. (Example 22)
A22. A constant is a fixed value that cannot be changed during the execution of a program. (Detailed explanation 22)
Q23. What is the use of #include<stdio.h>? (Example 23)
C Language Viva Questions & Answers - MSBTE K Scheme
A23. It tells the compiler to include the standard input-output library functions before actual compilation. (Detailed
explanation 23)
Q24. What are data types in C? (Example 24)
A24. Data types define the type of data a variable can hold, such as int, float, char, etc. (Detailed explanation 24)
Q25. What is the main() function? (Example 25)
A25. The main() function is the entry point of any C program. (Detailed explanation 25)
Unit 2: Control Structures
Q1. What are control structures?
A1. They control the flow of execution in a program such as if, if-else, switch, loops.
Q2. Explain the if-else statement.
A2. It allows conditional execution of code blocks based on a boolean expression.
Q3. What is the syntax of the switch statement?
A3. switch(expression) { case value: ... break; ... default: ... }
Q4. Difference between while and do-while loop?
A4. while checks the condition first; do-while executes the loop at least once.
Q5. What is a nested if?
A5. An if statement inside another if statement.
Q6. What is a loop?
A6. A loop allows executing a block of code multiple times.
Q7. Explain break statement.
A7. Used to exit from a loop or switch prematurely.
Q8. What is the continue statement?
A8. Skips the current iteration of a loop and moves to the next.
Q9. What is the purpose of goto?
A9. Transfers control to another part of the program using a label.
Q10. How many types of loops are there in C?
A10. Three: for, while, and do-while.
Q11. What are control structures? (Example 11)
A11. They control the flow of execution in a program such as if, if-else, switch, loops. (Detailed explanation 11)
Q12. Explain the if-else statement. (Example 12)
A12. It allows conditional execution of code blocks based on a boolean expression. (Detailed explanation 12)
Q13. What is the syntax of the switch statement? (Example 13)
A13. switch(expression) { case value: ... break; ... default: ... } (Detailed explanation 13)
Q14. Difference between while and do-while loop? (Example 14)
A14. while checks the condition first; do-while executes the loop at least once. (Detailed explanation 14)
Q15. What is a nested if? (Example 15)
A15. An if statement inside another if statement. (Detailed explanation 15)
Q16. What is a loop? (Example 16)
A16. A loop allows executing a block of code multiple times. (Detailed explanation 16)
Q17. Explain break statement. (Example 17)
A17. Used to exit from a loop or switch prematurely. (Detailed explanation 17)
Q18. What is the continue statement? (Example 18)
A18. Skips the current iteration of a loop and moves to the next. (Detailed explanation 18)
Q19. What is the purpose of goto? (Example 19)
A19. Transfers control to another part of the program using a label. (Detailed explanation 19)
Q20. How many types of loops are there in C? (Example 20)
A20. Three: for, while, and do-while. (Detailed explanation 20)
Q21. What are control structures? (Example 21)
C Language Viva Questions & Answers - MSBTE K Scheme
A21. They control the flow of execution in a program such as if, if-else, switch, loops. (Detailed explanation 21)
Q22. Explain the if-else statement. (Example 22)
A22. It allows conditional execution of code blocks based on a boolean expression. (Detailed explanation 22)
Q23. What is the syntax of the switch statement? (Example 23)
A23. switch(expression) { case value: ... break; ... default: ... } (Detailed explanation 23)
Q24. Difference between while and do-while loop? (Example 24)
A24. while checks the condition first; do-while executes the loop at least once. (Detailed explanation 24)
Q25. What is a nested if? (Example 25)
A25. An if statement inside another if statement. (Detailed explanation 25)
Unit 3: Arrays and Structures
Q1. What is an array?
A1. An array is a collection of elements of the same type stored in contiguous memory locations.
Q2. Syntax for declaring an array?
A2. datatype arrayName[size]; e.g., int marks[5];
Q3. What is a multidimensional array?
A3. An array with more than one index, e.g., a 2D array like int matrix[3][3];
Q4. What is a string in C?
A4. A string is an array of characters terminated by a null character '\0'.
Q5. How do you input a string?
A5. Using gets() or scanf() with %s format specifier.
Q6. What is a structure?
A6. A structure is a user-defined data type that groups related variables of different types.
Q7. How to declare a structure?
A7. struct StructName { data_type var1; ... };
Q8. Difference between array and structure?
A8. Arrays store elements of the same type, structures can store different types.
Q9. What is an array of structures?
A9. A collection of structure variables stored in an array.
Q10. How to access structure members?
A10. Using dot operator (.) for variables and arrow operator (->) for pointers.
Q11. What is an array? (Example 11)
A11. An array is a collection of elements of the same type stored in contiguous memory locations. (Detailed explanation
11)
Q12. Syntax for declaring an array? (Example 12)
A12. datatype arrayName[size]; e.g., int marks[5]; (Detailed explanation 12)
Q13. What is a multidimensional array? (Example 13)
A13. An array with more than one index, e.g., a 2D array like int matrix[3][3]; (Detailed explanation 13)
Q14. What is a string in C? (Example 14)
A14. A string is an array of characters terminated by a null character '\0'. (Detailed explanation 14)
Q15. How do you input a string? (Example 15)
A15. Using gets() or scanf() with %s format specifier. (Detailed explanation 15)
Q16. What is a structure? (Example 16)
A16. A structure is a user-defined data type that groups related variables of different types. (Detailed explanation 16)
Q17. How to declare a structure? (Example 17)
A17. struct StructName { data_type var1; ... }; (Detailed explanation 17)
Q18. Difference between array and structure? (Example 18)
A18. Arrays store elements of the same type, structures can store different types. (Detailed explanation 18)
Q19. What is an array of structures? (Example 19)
C Language Viva Questions & Answers - MSBTE K Scheme
A19. A collection of structure variables stored in an array. (Detailed explanation 19)
Q20. How to access structure members? (Example 20)
A20. Using dot operator (.) for variables and arrow operator (->) for pointers. (Detailed explanation 20)
Q21. What is an array? (Example 21)
A21. An array is a collection of elements of the same type stored in contiguous memory locations. (Detailed explanation
21)
Q22. Syntax for declaring an array? (Example 22)
A22. datatype arrayName[size]; e.g., int marks[5]; (Detailed explanation 22)
Q23. What is a multidimensional array? (Example 23)
A23. An array with more than one index, e.g., a 2D array like int matrix[3][3]; (Detailed explanation 23)
Q24. What is a string in C? (Example 24)
A24. A string is an array of characters terminated by a null character '\0'. (Detailed explanation 24)
Q25. How do you input a string? (Example 25)
A25. Using gets() or scanf() with %s format specifier. (Detailed explanation 25)
Unit 4: Functions
Q1. What is a function in C?
A1. A function is a block of code that performs a specific task.
Q2. What are the advantages of functions?
A2. Code reusability, modularity, easy debugging.
Q3. Syntax of a function definition?
A3. return_type function_name(parameter_list) { // body }
Q4. What is a return type?
A4. It defines what type of value a function will return.
Q5. What are actual and formal parameters?
A5. Actual are passed during function call; formal are received in function definition.
Q6. What is recursion?
A6. A function calling itself directly or indirectly.
Q7. Difference between call by value and call by reference?
A7. Call by value passes a copy; call by reference passes address.
Q8. What is function prototype?
A8. Declaration of a function before its actual definition.
Q9. What is scope of a variable?
A9. The region where a variable can be accessed.
Q10. What is a static function?
A10. A function with limited scope to the file in which it is declared.
Q11. What is a function in C? (Example 11)
A11. A function is a block of code that performs a specific task. (Detailed explanation 11)
Q12. What are the advantages of functions? (Example 12)
A12. Code reusability, modularity, easy debugging. (Detailed explanation 12)
Q13. Syntax of a function definition? (Example 13)
A13. return_type function_name(parameter_list) { // body } (Detailed explanation 13)
Q14. What is a return type? (Example 14)
A14. It defines what type of value a function will return. (Detailed explanation 14)
Q15. What are actual and formal parameters? (Example 15)
A15. Actual are passed during function call; formal are received in function definition. (Detailed explanation 15)
Q16. What is recursion? (Example 16)
A16. A function calling itself directly or indirectly. (Detailed explanation 16)
Q17. Difference between call by value and call by reference? (Example 17)
C Language Viva Questions & Answers - MSBTE K Scheme
A17. Call by value passes a copy; call by reference passes address. (Detailed explanation 17)
Q18. What is function prototype? (Example 18)
A18. Declaration of a function before its actual definition. (Detailed explanation 18)
Q19. What is scope of a variable? (Example 19)
A19. The region where a variable can be accessed. (Detailed explanation 19)
Q20. What is a static function? (Example 20)
A20. A function with limited scope to the file in which it is declared. (Detailed explanation 20)
Q21. What is a function in C? (Example 21)
A21. A function is a block of code that performs a specific task. (Detailed explanation 21)
Q22. What are the advantages of functions? (Example 22)
A22. Code reusability, modularity, easy debugging. (Detailed explanation 22)
Q23. Syntax of a function definition? (Example 23)
A23. return_type function_name(parameter_list) { // body } (Detailed explanation 23)
Q24. What is a return type? (Example 24)
A24. It defines what type of value a function will return. (Detailed explanation 24)
Q25. What are actual and formal parameters? (Example 25)
A25. Actual are passed during function call; formal are received in function definition. (Detailed explanation 25)
Unit 5: Pointers
Q1. What is a pointer?
A1. A pointer is a variable that stores the address of another variable.
Q2. How to declare a pointer?
A2. datatype *pointerName; e.g., int *ptr;
Q3. What is the use of & and *?
A3. & gives the address, * accesses the value at an address.
Q4. What is a null pointer?
A4. A pointer that does not point to any memory location.
Q5. What is pointer arithmetic?
A5. Operations like increment and decrement on pointers.
Q6. What is a dangling pointer?
A6. A pointer pointing to memory that has been freed or deleted.
Q7. What is pointer to pointer?
A7. A pointer that stores the address of another pointer.
Q8. What is a void pointer?
A8. A pointer that can hold address of any data type.
Q9. How are arrays and pointers related?
A9. Array name acts as a pointer to the first element.
Q10. How to pass pointer to a function?
A10. By passing its address as a parameter.
Q11. What is a pointer? (Example 11)
A11. A pointer is a variable that stores the address of another variable. (Detailed explanation 11)
Q12. How to declare a pointer? (Example 12)
A12. datatype *pointerName; e.g., int *ptr; (Detailed explanation 12)
Q13. What is the use of & and *? (Example 13)
A13. & gives the address, * accesses the value at an address. (Detailed explanation 13)
Q14. What is a null pointer? (Example 14)
A14. A pointer that does not point to any memory location. (Detailed explanation 14)
Q15. What is pointer arithmetic? (Example 15)
A15. Operations like increment and decrement on pointers. (Detailed explanation 15)
C Language Viva Questions & Answers - MSBTE K Scheme
Q16. What is a dangling pointer? (Example 16)
A16. A pointer pointing to memory that has been freed or deleted. (Detailed explanation 16)
Q17. What is pointer to pointer? (Example 17)
A17. A pointer that stores the address of another pointer. (Detailed explanation 17)
Q18. What is a void pointer? (Example 18)
A18. A pointer that can hold address of any data type. (Detailed explanation 18)
Q19. How are arrays and pointers related? (Example 19)
A19. Array name acts as a pointer to the first element. (Detailed explanation 19)
Q20. How to pass pointer to a function? (Example 20)
A20. By passing its address as a parameter. (Detailed explanation 20)
Q21. What is a pointer? (Example 21)
A21. A pointer is a variable that stores the address of another variable. (Detailed explanation 21)
Q22. How to declare a pointer? (Example 22)
A22. datatype *pointerName; e.g., int *ptr; (Detailed explanation 22)
Q23. What is the use of & and *? (Example 23)
A23. & gives the address, * accesses the value at an address. (Detailed explanation 23)
Q24. What is a null pointer? (Example 24)
A24. A pointer that does not point to any memory location. (Detailed explanation 24)
Q25. What is pointer arithmetic? (Example 25)
A25. Operations like increment and decrement on pointers. (Detailed explanation 25)
Unit 6: File Handling
Q1. What is file handling in C?
A1. File handling allows reading and writing data to files stored on disk.
Q2. What is FILE in C?
A2. It is a data type used to declare file pointers.
Q3. Functions for file operations?
A3. fopen(), fclose(), fprintf(), fscanf(), fgetc(), fputc() etc.
Q4. Modes in fopen()?
A4. "r", "w", "a", "r+", "w+", "a+" etc.
Q5. Difference between text and binary files?
A5. Text files are human-readable; binary files are not.
Q6. What is fgetc() and fputc()?
A6. fgetc reads a character from file, fputc writes a character.
Q7. How to write a string to file?
A7. Using fputs() or fprintf().
Q8. What is ftell()?
A8. Returns the current position in the file.
Q9. What is rewind()?
A9. Sets the file position to the beginning.
Q10. What is feof()?
A10. Checks if the end of the file has been reached.
Q11. What is file handling in C? (Example 11)
A11. File handling allows reading and writing data to files stored on disk. (Detailed explanation 11)
Q12. What is FILE in C? (Example 12)
A12. It is a data type used to declare file pointers. (Detailed explanation 12)
Q13. Functions for file operations? (Example 13)
A13. fopen(), fclose(), fprintf(), fscanf(), fgetc(), fputc() etc. (Detailed explanation 13)
Q14. Modes in fopen()? (Example 14)
C Language Viva Questions & Answers - MSBTE K Scheme
A14. "r", "w", "a", "r+", "w+", "a+" etc. (Detailed explanation 14)
Q15. Difference between text and binary files? (Example 15)
A15. Text files are human-readable; binary files are not. (Detailed explanation 15)
Q16. What is fgetc() and fputc()? (Example 16)
A16. fgetc reads a character from file, fputc writes a character. (Detailed explanation 16)
Q17. How to write a string to file? (Example 17)
A17. Using fputs() or fprintf(). (Detailed explanation 17)
Q18. What is ftell()? (Example 18)
A18. Returns the current position in the file. (Detailed explanation 18)
Q19. What is rewind()? (Example 19)
A19. Sets the file position to the beginning. (Detailed explanation 19)
Q20. What is feof()? (Example 20)
A20. Checks if the end of the file has been reached. (Detailed explanation 20)
Q21. What is file handling in C? (Example 21)
A21. File handling allows reading and writing data to files stored on disk. (Detailed explanation 21)
Q22. What is FILE in C? (Example 22)
A22. It is a data type used to declare file pointers. (Detailed explanation 22)
Q23. Functions for file operations? (Example 23)
A23. fopen(), fclose(), fprintf(), fscanf(), fgetc(), fputc() etc. (Detailed explanation 23)
Q24. Modes in fopen()? (Example 24)
A24. "r", "w", "a", "r+", "w+", "a+" etc. (Detailed explanation 24)
Q25. Difference between text and binary files? (Example 25)
A25. Text files are human-readable; binary files are not. (Detailed explanation 25)