0% found this document useful (0 votes)
9 views

C Viva Questions

The document contains a series of questions and answers related to the C programming language, covering topics such as storage classes, memory allocation, data types, functions, loops, and file handling. It provides concise explanations and distinctions between various C concepts, such as the differences between malloc and calloc, the use of pointers, and the characteristics of structures and unions. Overall, it serves as a comprehensive reference for fundamental C programming knowledge.

Uploaded by

harrsha93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

C Viva Questions

The document contains a series of questions and answers related to the C programming language, covering topics such as storage classes, memory allocation, data types, functions, loops, and file handling. It provides concise explanations and distinctions between various C concepts, such as the differences between malloc and calloc, the use of pointers, and the characteristics of structures and unions. Overall, it serves as a comprehensive reference for fundamental C programming knowledge.

Uploaded by

harrsha93
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1. 1. What is the output of printf("%d")?

Answer: 1. It produces an undefined result as no value is provided for %d.

2. 2. What are the different types of Storage classes?

Answer: 2. Storage classes in C are auto, register, static, and extern.

3. 3. Explain call by value and call by reference?

Answer: 3. Call by value passes a copy of the variable; call by reference passes the address.

4. 4. Why pre increment operator is faster than post increment?

Answer: 4. Pre-increment modifies the value before using it, reducing temporary storage needs.

5. 5. What is the difference between calloc and malloc?

Answer: 5. calloc() initializes memory to zero, malloc() does not.

6. 6. Can structures be passed to the functions by value?

Answer: 6. Yes, structures can be passed to functions by value.

7. 7. Why cannot arrays be passed by values to functions?

Answer: 7. Arrays are always passed by reference for efficiency.

8. 8. Difference between getchar() and fgetchar?

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.

10. 10. What is the scope of static variables?

Answer: 10. Static variables have file or block scope and persist for the program's lifetime.

11. 11. What are the types of constants available in C?

Answer: 11. Integer constants are decimal, octal, or hexadecimal.

12. 12. What is the range allowed for integer constants in 16-bit computers?

Answer: 12. 16-bit integer constants range from -32,768 to 32,767.


13. 13. What are the 2 ways of representing real constants?

Answer: 13. Real constants are in fractional or exponential form.

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.

15. 15. What are character constants?

Answer: 15. Character constants are enclosed in single quotes (e.g., 'A').

16. 16. How are character constants treated when used in arithmetic expressions?

Answer: 16. Character constants are treated as integers in arithmetic.

17. 17. Why is C called a middle-level language?

Answer: 17. C is middle-level as it supports high-level and low-level features.

18. 18. What value does a variable assume if it is not initialized?

Answer: 18. Variables assume garbage values if not initialized.

19. 19. What is the default scope of if statement?

Answer: 19. If statements have block scope.

20. 20. Which are the logical operators available in C? Why do we need them?

Answer: 20. Logical operators are &&, ||, and !; used for conditions.

21. 21. What is a conditional operator?

Answer: 21. Conditional operators are ternary (e.g., ?:).

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.

23. 23. Can you use multiple conditions in for loop?

Answer: 23. Yes, multiple conditions can be used in a for loop.

24. 24. What do you mean by an odd loop?


Answer: 24. Odd loops run indefinitely due to incorrect conditions.

25. 25. What is the use of break statement?

Answer: 25. Break exits a loop prematurely.

26. 26. Where do we use continue keyword?

Answer: 26. Continue skips the rest of the loop iteration.

27. 27. Do the cases in switch statement need to be arranged in ascending order?

Answer: 27. No, switch cases can be in any order.

28. 28. What is the advantage of switch over if statement?

Answer: 28. Switch is cleaner than if for multiple cases.

29. 29. Can we use expressions yielding floating-point values in switch statements?

Answer: 29. No, switch only accepts integers.

30. 30. What is the meaning of while(1)?

Answer: 30. while(1) creates an infinite loop.

31. 31. What is a function? Why do we need them?

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?

Answer: 32. Functions can be called unlimited times.

33. 33. What is the use of return statement?

Answer: 33. Return ends function execution and sends a value.

34. 34. Is it possible for a function to return more than one value at a time?

Answer: 34. Functions cannot return multiple values directly.

35. 35. What is the default return value of any function in C?

Answer: 35. Default return value of main is 0 (success).

36. 36. Value at address operator is also called?


Answer: 36. The value at address operator is also * (dereference).

37. 37. What are pointers?

Answer: 37. Pointers store memory addresses.

38. 38. What is recursion? What are its applications?

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: 39. Recursion uses stack; iterative is loop-based.

40. 40. What is a preprocessor?

Answer: 40. A preprocessor processes code before compilation.

41. 41. What is a macro?

Answer: 41. Macros are preprocessor directives for constants or inline code.

42. 42. What do you mean by conditional compilation?

Answer: 42. Conditional compilation allows selective compilation using #ifdef, etc.

43. 43. Why is C called a free form language?

Answer: 43. C is free form as it ignores whitespace.

44. 44. What are identifiers?

Answer: 44. Identifiers are variable or function names.

45. 45. What are string constants?

Answer: 45. String constants are text enclosed in double quotes.

46. 46. What are escape sequences? Give examples?

Answer: 46. Escape sequences are special characters like \n, \t.

47. 47. Name some of the qualifiers used with fundamental data types?

Answer: 47. Qualifiers: const, volatile, signed, unsigned.

48. 48. What is the use of the comma operator in C?


Answer: 48. Comma operator evaluates multiple expressions.

49. 49. Explain the use of sizeof() operator?

Answer: 49. sizeof() gives size of a data type or variable.

50. 50. What do you mean by associativity property of an operator?

Answer: 50. Associativity determines evaluation order for operators.

51. 51. Name some of the character test functions.

Answer: 51. Character test functions: isalpha(), isdigit(), etc.

52. 52. How is left-justification achieved while printing variable values?

Answer: 52. Left-justification uses %- formatting in printf.

53. 53. What are arrays?

Answer: 53. Arrays store collections of similar data types.

54. 54. How do you initialize arrays?

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?

Answer: 55. Column dimension ensures memory allocation in 2D arrays.

56. 56. Which function is used to accept multiword strings?

Answer: 56. gets() accepts multiword strings but is unsafe.

57. 57. Name some of the most commonly used string-handling functions?

Answer: 57. String functions: strcpy(), strlen(), strcat().

58. 58. What is the difference between array of pointers to strings and 2-d array of characters?

Answer: 58. Array of pointers saves memory; 2D arrays are contiguous.

59. 59. What is a structure?

Answer: 59. Structures group different data types.

60. 60. Can a structure be assigned to another using assignment operator?


Answer: 60. Yes, structures can be assigned to another.

61. 61. What are unions?

Answer: 61. Unions share memory for members.

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?

Answer: 63. Bit fields save memory in structures.

64. 64. Can we increment or decrement pointers? If yes, what actually happens?

Answer: 64. Yes, pointer arithmetic moves to next memory location.

65. 65. What is a file?

Answer: 65. Files store data persistently.

66. 66. What is the difference between printf() and sprintf() functions?

Answer: 66. printf() outputs to console; sprintf() writes to a string.

67. 67. What is the difference between getch() and getche()?

Answer: 67. getch() doesn't echo input; getche() does.

68. 68. Difference between getchar() and fgetchar()?

Answer: 68. getchar() and fgetchar() both read characters from stdin.

69. 69. Which are the different modes of opening a file?

Answer: 69. File modes: r, w, a, r+, w+, a+.

70. 70. What are command line arguments? Explain.

Answer: 70. Command-line arguments pass inputs at runtime.

71. 71. Mention the functions used in random access to files.

Answer: 71. Random access: fseek(), ftell(), rewind().

72. 72. What is the syntax of fseek() function?


Answer: 72. fseek(file, offset, origin);

73. 73. Mention some functions used to handle errors during I/O operations on files.

Answer: 73. Error functions: ferror(), clearerr(), perror().

74. 74. Mention the bitwise operators available in C.

Answer: 74. Bitwise operators: &, |, ^, ~, <<, >>.

75. 75. Can bitwise operators operate upon floats and doubles?

Answer: 75. No, they only operate on integers.

76. 76. Mention the real-time applications of bitwise operators.

Answer: 76. Real-time: masking, toggling, compression.

77. 77. What are enumerated data types?

Answer: 77. Enumerated types name integer constants.

78. 78. What is the purpose of typedef declarations?

Answer: 78. Typedef creates type aliases.

79. 79. What is type casting?

Answer: 79. Type casting converts data types.

80. 80. What is dynamic memory allocation?

Answer: 80. Dynamic memory allocation allocates runtime memory.

81. 81. Which are the memory management functions available in C?

Answer: 81. Memory functions: malloc(), calloc(), realloc(), free().

82. 82. What is heap?

Answer: 82. Heap is a memory area for dynamic allocation.

83. 83. What are the differences between static and dynamic memory allocations?

Answer: 83. Static: compile-time; Dynamic: runtime.

84. 84. What is the syntax of realloc()?


Answer: 84. realloc(ptr, new_size);

85. 85. What is searching?

Answer: 85. Searching locates a value in data.

86. 86. What is sorting?

Answer: 86. Sorting arranges data in order.

87. 87. Where actually does the C program execution begin?

Answer: 87. Execution begins in main().

88. 88. What is a syntax error?

Answer: 88. Syntax errors break language rules.

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

Answer: 89. while checks before; do-while after iteration.

90. 90. What is ANSI?

Answer: 90. ANSI standardizes programming languages.

91. 91. List out conditional and unconditional directives.

Answer: 91. Conditional: #if; Unconditional: #define.

92. 92. What is the difference between void main() and int main()?

Answer: 92. int main() is standard; void main() is not.

93. 93. What are the type qualifiers/modifiers?

Answer: 93. Qualifiers: const, volatile, signed.

94. 94. What is pointer on pointer?

Answer: 94. Pointer on pointer stores another pointer's address.

95. 95. What is the meaning of base address of the array?

Answer: 95. Base address is the first array element's address.

96. 96. What is lvalue and rvalue?


Answer: 96. lvalue: memory object; rvalue: temporary value.

97. 97. Explain modular programming.

Answer: 97. Modular programming divides code into functions.

98. 98. Is FILE a built-in data type?

Answer: 98. FILE is a typedef for struct.

99. 99. Which keyword is used to perform unconditional branching?

Answer: 99. goto performs unconditional branching.

100. 100. Can we assign a float variable to a long integer variable?

Answer: 100. Yes, but float truncates when assigned to long.

You might also like