Study

C++ coding

  •   0%
  •  0     0     0

  • True or false: A float variable can store whole numbers.
    True (though it is usually used for decimal values).
  • True or False: You must declare a variable before you use it in C++.
    True.
  • What happens if you don’t include using namespace std;?
    You must write std::cout and std::cin instead of cout and cin.
  • Complete the sentence: The main() function is the ________ point of a C++ program.
    starting
  • Name two basic variable types in C++.
    string, int, float
  • What's wrong with this code?
    Missing a semicolon after endl
  • Fill in the blank: In C++, the ________ keyword is used to declare a variable that stores text.
    string
  • What will this code output?
    Hello, Alice!
  • What will happen if you forget the return 0; statement in main()?
    In most modern compilers, the program will still run, as it assumes return 0;, but it’s good practice to include it.
  • What will this code output?
    look at the board
  • True or False: A string variable can hold numbers as well as text.
    True. (Numbers in string are treated as text.)
  • What will this code output?
    The result of a / 2 is: 7
  • What will this code output?
  • Which variable type would you use to store the following: a person's age
    int
  • True or False: The int data type can store decimal values.
    False.
  • If you want to store the number 3.14, which data type would you use?
    float
  • Fill in the blanks to make this code work:
    <iostream>, std, main
  • Which variable type would you use to store the following: a person's height in meters
    float
  • Which variable type would you use to store the following: a person's name
    string
  • Complete the sentence: The ______ keyword moves the output to the next line
    endl
  • What's wrong with this code?
    Missing a semicolon after endl