C - Basics Practice Test.2

  1. What is a constant in C?

    A) A variable that can change its value

    B) A reserved keyword

    C) A storage location for data

    D) A value that cannot be altered during program execution

    Answer: D) A value that cannot be altered during program execution

  2. Which keyword is used to define a constant in C?

    A) const

    B) constant

    C) define

    D) var

    Answer: A) const

  3. What is the advantage of using constants in C?

    A) They can be changed easily

    B) They consume less memory

    C) They make the code more readable and maintainable

    D) They can only hold integer values

    Answer: C) They make the code more readable and maintainable

  4. Which of the following is a valid way to define a constant integer in C?

    A) constant int num = 42;

    B) const num = 42;

    C) int num = const 42;

    D) const int num = 42;

    Answer: D) const int num = 42;

  5. Can you change the value of a constant after it is defined in C?

    A) Yes, at any time

    B) No, it is not allowed

    C) Only in certain conditions

    D) Yes, but with restrictions

    Answer: B) No, it is not allowed

  6. What is the naming convention for naming constants in C?

    A) UPPERCASE_WITH_UNDERSCORES

    B) CamelCase

    C) lowercase

    D) PascalCase

    Answer: A) UPPERCASE_WITH_UNDERSCORES

  7. Which of the following is a valid constant value for representing the mathematical constant Pi (π) in C?

    A) 3.14159

    B) "Pi"

    C) 22/7

    D) pi_value

    Answer: A) 3.14159

  8. How do you assign a value to a constant in C?

    A) Using the assignment operator (=)

    B) Using the define keyword

    C) Using the const keyword

    D) Constants do not require assignment

    Answer: A) Using the assignment operator (=)

  9. What is the scope of a constant in C?

    A) Limited to the function in which it is defined

    B) Accessible from any function in the program

    C) Limited to the block of code in which it is defined

    D) Accessible from any file in the program

    Answer: A) Limited to the function in which it is defined

  10. Which data type is commonly used for defining floating-point constants in C?

    A) int

    B) double

    C) char

    D) float

    Answer: B) double

  11. What is an identifier in C?

    A) A reserved keyword

    B) A variable with a specific value

    C) A name used to identify variables, functions, or other entities

    D) A data type

    Answer: C) A name used to identify variables, functions, or other entities

  12. Which of the following is a valid C identifier?

    A) 123identifier

    B) _myIdentifier

    C) break

    D) my-identifier

    Answer: B) _myIdentifier

  13. Can C identifiers start with a digit?

    A) Yes

    B) No, they must start with a letter

    C) Only if they are constant identifiers

    D) Only if they are function names

    Answer: B) No, they must start with a letter

  14. What is the maximum length of a C identifier?

    A) 16 characters

    B) 32 characters

    C) 64 characters

    D) There is no fixed limit

    Answer: D) There is no fixed limit

  15. Which of the following is not a valid identifier in C?

    A) main_function

    B) my-identifier

    C) _variable123

    D) int

    Answer: B) my-identifier

  16. Are C identifiers case-sensitive?

    A) Yes

    B) No, they are case-insensitive

    C) Case-sensitivity depends on the compiler

    D) Only variable names are case-sensitive

    Answer: A) Yes

  17. Which of the following is a valid way to declare a constant identifier in C?

    A) constant int num = 42;

    B) const num = 42;

    C) int const num = 42;

    D) const int num = 42;

    Answer: D) const int num = 42;

  18. What is the naming convention for variable names in C?

    A) CamelCase

    B) lowercase_with_underscores

    C) UPPERCASE_WITH_UNDERSCORES

    D) PascalCase

    Answer: B) lowercase_with_underscores

  19. Which of the following is a valid C function name?

    A) 123Function

    B) my function

    C) _calculate_sum

    D) return

    Answer: C) _calculate_sum

  20. What happens if you use a reserved keyword as an identifier in C?

    A) It is allowed, and the keyword retains its original meaning

    B) It is allowed, but the keyword loses its original meaning

    C) It is not allowed; it results in a compilation error

    D) It is allowed, but only in user-defined functions

    Answer: C) It is not allowed; it results in a compilation error

  21. What is a literal in C?

    A) A function that performs a specific task

    B) A value that is used directly in the code

    C) A variable declaration

    D) A comment that explains the code

    Answer: B) A value that is used directly in the code

  22. Which of the following is a valid integer literal in C?

    A) 3.14

    B) 0x1A

    C) 'A'

    D) "Hello"

    Answer: B) 0x1A

  23. What type of literal represents a single character in C?

    A) String literal

    B) Integer literal

    C) Character literal

    D) Float literal

    Answer: C) Character literal

  24. How can you represent a floating-point literal in C?

    A) 42

    B) 3.14f

    C) 'A'

    D) 0x1A

    Answer: B) 3.14f

  25. What is the purpose of a string literal in C?

    A) To represent a sequence of characters

    B) To define a numeric value

    C) To declare a variable

    D) To perform arithmetic operations

    Answer: A) To represent a sequence of characters

  26. Which of the following is a valid string literal in C?

    A) 'Hello'

    B) "Hello, World!"

    C) 42

    D) 3.14

    Answer: B) "Hello, World!"

  27. How can you represent an octal (base 8) integer literal in C?

    A) 0x1A

    B) 42

    C) 075

    D) 3.14

    Answer: C) 075

  28. What is the purpose of a hexadecimal (base 16) literal in C?

    A) To represent a fraction

    B) To declare a character

    C) To define a sequence of characters

    D) To specify values in a different base

    Answer: D) To specify values in a different base

  29. Which type of literal is used for representing a true or false value in C?

    A) Integer literal

    B) Boolean literal

    C) Character literal

    D) String literal

    Answer: A) Integer literal

  30. How can you represent a true value in C?

    A) 0

    B) 1

    C) 'T'

    D) "True"

    Answer: B) 1

  31. What is the purpose of comments in C?

    A) To add decorative elements to the code

    B) To provide explanations and annotations for the code

    C) To declare variables and functions

    D) To specify the program's entry point

    Answer: B) To provide explanations and annotations for the code

  32. Which symbol is used to begin a single-line comment in C?

    A) ;

    B) //

    C) #

    D) /*

    Answer: B) //

  33. How can you create a multi-line comment in C?

    A) Using a pair of forward slashes (//)

    B) Using a pair of curly braces ({})

    C) Using a pair of angle brackets (<>)

    D) Using /* to start and */ to end the comment

    Answer: D) Using /* to start and */ to end the comment

  34. What is the purpose of including comments in your code?

    A) To make the code execute faster

    B) To confuse other programmers

    C) To improve code readability and understandability

    D) To hide the code from the compiler

    Answer: C) To improve code readability and understandability

  35. Which of the following is a valid single-line comment in C?

    A) /This is a comment/

    B) // This is a comment

    C) /* This is a comment */

    D) # This is a comment

    Answer: B) // This is a comment

  36. What happens to comments when the C code is compiled?

    A) Comments are executed as part of the program

    B) Comments are ignored by the compiler

    C) Comments are converted into machine code

    D) Comments generate compilation errors

    Answer: B) Comments are ignored by the compiler

  37. Which type of comment is typically used for documentation purposes in C?

    A) Single-line comments

    B) Multi-line comments

    C) Block comments

    D) Doxygen comments

    Answer: D) Doxygen comments

  38. When should you use comments in your code?

    A) Only when the code has errors

    B) Whenever you feel like it

    C) Only in the main function

    D) To explain complex logic or provide context

    Answer: D) To explain complex logic or provide context

  39. Which of the following is a correct way to comment out a block of code in C?

    A) Using a pair of angle brackets (<>)

    B) Using // before each line of code

    C) Using /* to start and */ to end the block

    D) Using a pair of curly braces ({})

    Answer: C) Using /* to start and */ to end the block

  40. What is the recommended practice for writing meaningful comments in C?

    A) Use cryptic and abbreviated language

    B) Avoid commenting altogether to keep the code concise

    C) Write clear and concise comments that explain the why, not just the what

    D) Write comments only for code that is difficult to understand

    Answer: C) Write clear and concise comments that explain the why, not just the what

  41. What are keywords in C?

    A) Words that are reserved for special functions and cannot be used as identifiers

    B) Words used for naming variables and functions

    C) Words used to create comments in the code

    D) Words used to define data types

    Answer: A) Words that are reserved for special functions and cannot be used as identifiers

  42. Which of the following is not a C keyword?

    A) int

    B) for

    C) begin

    D) while

    Answer: C) begin

  43. What is the purpose of keywords in C?

    A) To make the code more confusing

    B) To create user-defined data types

    C) To specify the structure of the program

    D) To convey special meanings and functionality to the compiler

    Answer: D) To convey special meanings and functionality to the compiler

  44. Which keyword is used to define a function in C?

    A) def

    B) func

    C) function

    D) void

    Answer: D) void

  45. What is the significance of the "auto" keyword in C?

    A) It specifies automatic memory allocation for variables

    B) It defines automatic functions

    C) It represents an autonomous program

    D) It is not a valid C keyword

    Answer: A) It specifies automatic memory allocation for variables

  46. Which keyword is used to declare a constant in C?

    A) var

    B) constant

    C) const

    D) define

    Answer: C) const

  47. What is the purpose of the "volatile" keyword in C?

    A) It indicates a variable that can be changed by external factors

    B) It specifies a variable that cannot be modified

    C) It defines a variable with a volatile data type

    D) It is used to declare volatile functions

    Answer: A) It indicates a variable that can be changed by external factors

  48. Which keyword is used to exit a loop prematurely in C?

    A) stop

    B) break

    C) exit

    D) quit

    Answer: B) break

  49. What does the "static" keyword do in C?

    A) It declares a variable with dynamic memory allocation

    B) It specifies that a variable retains its value between function calls

    C) It defines a variable with constant values

    D) It is not a valid C keyword

    Answer: B) It specifies that a variable retains its value between function calls

  50. Which keyword is used to access the members of a structure in C?

    A) member

    B) dot

    C) access

    D) struct

    Answer: B) dot