Q. What is the output of the following C++ program?

Code:
#include <iostream>
using namespace std;
int main()
{
  cout << sizeof(char);
  cout << sizeof(int);
  cout << sizeof(float);
  return 0;
}
  • (A) 1 8 8
  • (B) 1 4 8
  • (C) 1 4 4
  • (D) None of the above
πŸ’¬ Discuss
βœ… Correct Answer: (C) 1 4 4

Q. Which function is used to read a single character in the console in C++?

  • (A) scanf(c)
  • (B) read(c)
  • (C) getline(c)
  • (D) cin.get(c)
πŸ’¬ Discuss
βœ… Correct Answer: (D) cin.get(c)
Explanation: In C , the cin.get() function reads a single character from the console.

Q. Which function is used to write a single character to the console in C++?

  • (A) printf(c)
  • (B) write(c)
  • (C) cout.put(c)
  • (D) cout.putline(c)
πŸ’¬ Discuss
βœ… Correct Answer: (C) cout.put(c)
Explanation: In C , the cout.put() function writes a single character to the console.

Q. The size of an object or type can be determined with which operator?

  • (A) malloc
  • (B) sizeof
  • (C) malloc
  • (D) calloc
πŸ’¬ Discuss
βœ… Correct Answer: (B) sizeof
Explanation: The sizeof operator gives the size of an object or type.

Q. Which of the following are true about static member function?

1. They can access non-static data members.
2. They can call only other static member functions.
3. They can access global functions and data.
4. They can have this pointer.
5. They cannot be declared as const or volatile.

  • (A) Only 2
  • (B) Only 2,5
  • (C) Only 2,3,4,5
  • (D) Only 2 , 3 , 5
πŸ’¬ Discuss
βœ… Correct Answer: (D) Only 2 , 3 , 5

Q. class X, class Y and class Z are derived from class BASE. This is ______ inheritance.

  • (A) Multiple
  • (B) Multilevel
  • (C) Hierarchical
  • (D) Single
πŸ’¬ Discuss
βœ… Correct Answer: (C) Hierarchical

Q. When base class is derived in protected mode, then_____________ .

1. public members of base class become private members of derived class.
2. public members of base class become protected members of derived class.
3. public members of base class become public members of derived class.
4. protected members of base class become protected members of derived class.
5. protected members of base class become private members of derived class.
6. protected members of base class become public members of derived class.

  • (A) Only 1, 5
  • (B) Only 1, 6
  • (C) Only 2, 6
  • (D) Only 2, 4
πŸ’¬ Discuss
βœ… Correct Answer: (D) Only 2, 4

Q. Streams that will be performing both input and output operations must be declared as class _________ .

  • (A) iostream
  • (B) fstream
  • (C) stdstream
  • (D) Stdiostream
πŸ’¬ Discuss
βœ… Correct Answer: (B) fstream

Q. Exception handlers are declared with ____________ keyword.

  • (A) Try
  • (B) catch
  • (C) throw
  • (D) Finally
πŸ’¬ Discuss
βœ… Correct Answer: (B) catch

Q. How many times does the “cout” in line 12 run?

Code:
#include  
using namespace std; 
  
int main() 
{ 
    int n = 10; 
    for (int i = 0; i < n; i++ ) 
    { 
        n++; 
        continue; 
        cout << n; 
    } 
  
    return 1;
}
  • (A) 10
  • (B) 11
  • (C) 1
  • (D) The “cout” never runs.
πŸ’¬ Discuss
βœ… Correct Answer: (D) The “cout” never runs.
Explanation: The “continue” instruction will never let the “cout” instruction be executed and therefore never executed.