C Viva Questions
C Viva Questions
Answer: 3. Call by value passes a copy of the variable; call by reference passes the address.
Answer: 4. Pre-increment modifies the value before using it, reducing temporary storage needs.
Answer: 8. getchar() reads from stdin; fgetchar() is similar but explicitly for stdin.
9. 9. What are the advantages and disadvantages of using macros over functions?
Answer: 9. Macros are faster but lack type checking; functions are type-safe.
Answer: 10. Static variables have file or block scope and persist for the program's lifetime.
12. 12. What is the range allowed for integer constants in 16-bit computers?
14. 14. What is the range for real constants expressed in exponential form?
Answer: 14. Exponential real constants range between 3.4e-38 and 3.4e+38.
Answer: 15. Character constants are enclosed in single quotes (e.g., 'A').
16. 16. How are character constants treated when used in arithmetic expressions?
20. 20. Which are the logical operators available in C? Why do we need them?
Answer: 20. Logical operators are &&, ||, and !; used for conditions.
22. 22. When do you use while, do-while, and for loops?
Answer: 22. Use while for uncertain iterations, do-while for at least one execution, and for for
definite iterations.
27. 27. Do the cases in switch statement need to be arranged in ascending order?
29. 29. Can we use expressions yielding floating-point values in switch statements?
Answer: 31. Functions modularize the code for reuse and readability.
32. 32. Is there any restriction on the number of times a function can be called?
34. 34. Is it possible for a function to return more than one value at a time?
Answer: 38. Recursion is a function calling itself; used for trees, factorials, etc.
39. 39. What are the differences between recursion and iterative procedures?
Answer: 41. Macros are preprocessor directives for constants or inline code.
Answer: 42. Conditional compilation allows selective compilation using #ifdef, etc.
Answer: 46. Escape sequences are special characters like \n, \t.
47. 47. Name some of the qualifiers used with fundamental data types?
Answer: 54. Arrays are initialized with curly braces (e.g., int arr[] = {1, 2}).
55. 55. Why is it compulsory to mention the column dimension in a 2-d array?
57. 57. Name some of the most commonly used string-handling functions?
58. 58. What is the difference between array of pointers to strings and 2-d array of characters?
62. 62. What are the differences between structures and unions?
Answer: 62. Structures store all members; unions store one at a time.
63. 63. What are bit fields? Why are they used?
64. 64. Can we increment or decrement pointers? If yes, what actually happens?
66. 66. What is the difference between printf() and sprintf() functions?
Answer: 68. getchar() and fgetchar() both read characters from stdin.
73. 73. Mention some functions used to handle errors during I/O operations on files.
75. 75. Can bitwise operators operate upon floats and doubles?
83. 83. What are the differences between static and dynamic memory allocations?
89. 89. What is the difference between while loop and do-while loop?
92. 92. What is the difference between void main() and int main()?