C - Basics Practice Test.5

  1. What are runtime errors in C programming?

    A) Errors that occur during code compilation

    B) Errors that are reported by the preprocessor

    C) Errors that happen during program execution

    D) Errors that are detected by the debugger

    Answer: C) Errors that happen during program execution

  2. When do runtime errors typically occur in a C program?

    A) During code writing and editing

    B) During the preprocessing stage

    C) During code compilation

    D) While the program is running

    Answer: D) While the program is running

  3. Which of the following is a common example of a runtime error?

    A) Syntax error

    B) Type mismatch error

    C) Division by zero

    D) Missing header file

    Answer: C) Division by zero

  4. What does a "segmentation fault" runtime error indicate?

    A) A syntax error in the code

    B) An issue with memory allocation

    C) An infinite loop in the program

    D) A problem with the function prototypes

    Answer: B) An issue with memory allocation

  5. How can you handle runtime errors in C programs?

    A) By ignoring them; they don't affect program execution

    B) By adding more comments to the code

    C) By using exception handling mechanisms

    D) By increasing the program's execution speed

    Answer: C) By using exception handling mechanisms

  6. What is the purpose of exception handling in C?

    A) To create more runtime errors

    B) To ignore all runtime errors

    C) To gracefully handle and recover from runtime errors

    D) To disable runtime error reporting

    Answer: C) To gracefully handle and recover from runtime errors

  7. Which C library function can be used to exit a program when a runtime error occurs?

    A) `main`

    B) `exit`

    C) `printf`

    D) `return`

    Answer: B) `exit`

  8. What is a "null pointer dereference" runtime error?

    A) A type mismatch error

    B) A division by zero error

    C) An attempt to access or modify data through a null pointer

    D) An error caused by an uninitialized variable

    Answer: C) An attempt to access or modify data through a null pointer

  9. Which of the following can help prevent runtime errors in C programs?

    A) Increasing the code complexity

    B) Adding more comments to the code

    C) Properly validating user input

    D) Ignoring all compiler warnings

    Answer: C) Properly validating user input

  10. What should you do when you encounter a runtime error in a C program?

    A) Ignore it and continue program execution

    B) Debug the program to identify the issue

    C) Disable the compiler's error checking features

    D) Delete the section of code causing the error

    Answer: B) Debug the program to identify the issue

  11. What are logical errors in programming?

    A) Errors that occur during code compilation

    B) Errors that are reported by the preprocessor

    C) Errors that affect the program's logic and produce incorrect results

    D) Errors that are detected by the debugger

    Answer: C) Errors that affect the program's logic and produce incorrect results

  12. When do logical errors typically occur in a program?

    A) During code writing and editing

    B) During the preprocessing stage

    C) During code compilation

    D) During program execution

    Answer: D) During program execution

  13. Which of the following is a common example of a logical error?

    A) Syntax error

    B) Type mismatch error

    C) Division by zero

    D) Incorrect calculation or decision-making in the code

    Answer: D) Incorrect calculation or decision-making in the code

  14. How can you detect logical errors in your code?

    A) By relying on the compiler to find them

    B) By adding more comments to the code

    C) By performing thorough testing and debugging

    D) By disabling error checking in the compiler settings

    Answer: C) By performing thorough testing and debugging

  15. What is the primary purpose of debugging tools in programming?

    A) To introduce more errors into the code

    B) To generate documentation for the code

    C) To identify and fix errors, including logical errors

    D) To improve code performance

    Answer: C) To identify and fix errors, including logical errors

  16. What happens when a logical error occurs in a program?

    A) The program crashes with an error message.

    B) The program executes without any issues.

    C) The program produces incorrect results or behaves unexpectedly.

    D) The program's compilation fails.

    Answer: C) The program produces incorrect results or behaves unexpectedly.

  17. Which of the following strategies can help prevent logical errors in your code?

    A) Ignoring error messages during compilation

    B) Writing longer and more complex code

    C) Performing code reviews and testing

    D) Using only one programming language

    Answer: C) Performing code reviews and testing

  18. What is the role of unit testing in detecting logical errors?

    A) Unit testing cannot detect logical errors.

    B) Unit testing focuses only on syntax errors.

    C) Unit testing exercises specific parts of the code to uncover logic issues.

    D) Unit testing is used for optimizing code performance.

    Answer: C) Unit testing exercises specific parts of the code to uncover logic issues.

  19. When a logical error is discovered in a program, what should be the next step?

    A) Ignore the error; it's not important.

    B) Document the error and continue using the program.

    C) Fix the error by modifying the code.

    D) Disable the compiler's error checking features.

    Answer: C) Fix the error by modifying the code.

  20. Which phase of the software development process is most suitable for catching logical errors?

    A) Design

    B) Coding

    C) Testing

    D) Deployment

    Answer: C) Testing

  21. What is the primary difference between compile time and runtime in programming?

    A) Compile time refers to program execution, while runtime refers to code translation.

    B) Compile time is the time taken by the CPU to execute the program, while runtime is the time taken to write the code.

    C) Compile time occurs before program execution, while runtime occurs during program execution.

    D) Compile time and runtime are the same concepts and can be used interchangeably.

    Answer: C) Compile time occurs before program execution, while runtime occurs during program execution.

  22. When does compile time occur in the software development process?

    A) After the program is executed

    B) During program execution

    C) Before program execution, during the compilation phase

    D) After program execution, during debugging

    Answer: C) Before program execution, during the compilation phase.

  23. What is the purpose of the compiler during compile time?

    A) To execute the program

    B) To generate machine code from the source code

    C) To detect and handle runtime errors

    D) To optimize the code for better performance

    Answer: B) To generate machine code from the source code.

  24. Which of the following is an example of a compile-time error?

    A) Division by zero

    B) Incorrectly spelled variable name

    C) Memory allocation failure

    D) Array index out of bounds

    Answer: B) Incorrectly spelled variable name.

  25. What is runtime in the context of programming?

    A) The time it takes to write code

    B) The time it takes for a program to execute

    C) The time it takes for the compiler to translate code

    D) The time it takes to debug a program

    Answer: B) The time it takes for a program to execute.

  26. Which of the following is an example of a runtime error?

    A) Syntax error in the code

    B) Memory leak

    C) Missing semicolon at the end of a statement

    D) Incorrect file path specified in the code

    Answer: B) Memory leak.

  27. Can compile-time errors be detected without executing the program?

    A) Yes, they are detected during the program execution.

    B) No, they can only be detected by running the program.

    C) Yes, they are detected during the compilation phase.

    D) No, they are not errors but warnings.

    Answer: C) Yes, they are detected during the compilation phase.

  28. Which phase of the software development process is most concerned with compile-time errors?

    A) Design phase

    B) Testing phase

    C) Coding phase

    D) Deployment phase

    Answer: C) Coding phase.

  29. What is the typical outcome of a compile-time error?

    A) The program crashes with an error message.

    B) The program executes successfully.

    C) The error is detected and reported by the compiler.

    D) The error is silently ignored.

    Answer: C) The error is detected and reported by the compiler.

  30. In which phase can you fix compile-time errors?

    A) Design phase

    B) Testing phase

    C) Coding phase

    D) Deployment phase

    Answer: C) Coding phase.