Basics of C++

  1. C++ is an extension of C language. One of the new features added is:
    • Structure
    • Union
    • Operator overloading
    • Function
  2. Which of the following statements is FALSE?
    • In a C++ program, the execution begins at main() function.
    • Every C++ program must have a main() function.
    • Every C++ statement must end with a semicolon.
    • C++ does not permit the use of printf() for displaying an output.
  3. Line commands are inserted into a C++ program using
    • Left and right curly brackets like {…}
    • Double forward slashes like //…..
    • Stars and slashes like /*..…*/
    • A colon like this : …..
  4. For declaring the variables a and b, which of the following declaration statements is incorrect?
    • int a, b; // Declaration
    • int a, /* Declaration*/ b;
    • int a, // Declaration // b;
    • int a, b; // Declaration //
  5. For using functions that convert numbers to text and text to numbers, we must include the following header file:
    • <cstdlib>
    • <iostream>
    • <cstdio>
    • <cmath>
  6. Which of the following statements provide two lines of output?
    • cout << ”VERY” << “GOOD”;
    • cout << ”VERY” “\n” << “GOOD” “\n”;
    • cout << “VERY”<< “GOOD” “\n”;
    • cout << ”\nVERY” /*First line */ << “GOOD”; // Second line
  7. Which of the following statements is invalid in C++?
    • cin >> count;
    • cin >> x; >>y;
    • cin >> x // >> y;
    • cin >> x >>y;
  8. Which of the following statements requires the header file <math.h> to be included?
    • cout <<x/y;
    • x + = 10;
    • x = m*n+1;
    • x = sqrt(y);
  9. Name the header file that is to be used in the #include directive when we use cout for displaying outputs.
    • <cstdio>
    • <cstdlib>
    • <iostrean>
    • <cassert>
  10. If a is an object of the class B and void print (void) is a member function of B, then which one of the following statements will invoke the function?
    • a::print();
    • a.voidprint();
    • B.print();
    • a.print();

Answers:

  1. Operator overloading
  2. C++ does not permit the use of printf() for displaying an output.
  3. Double forward slashes like //…..
  4. int a, // Declaration // b;
  5. <iostream>
  6. cout << ”VERY” “\n” << “GOOD” “\n”;
  7. cin >> x; >>y;
  8. x = sqrt(y);
  9. <iostrean>
  10. a.print();

Related posts