Home »
Aptitude Questions and Answers »
C++ Aptitude Questions and Answers
C++ cin, cout Aptitude Questions and Answers
C++ cin, cout Aptitude: This section contains C++ cin, cout aptitude questions and answers with explanations.
Submitted by Nidhi, on February 17, 2021
1) Which of the following is known as the insertion operator in C++?
- <<
- >>
- ~
- ^^
Correct Answer - 1
<<
Explanation:
The "<<" operator is known as an insertion operator in C++.
2) Which of the following is known as exertion operator in C++?
- <<
- >>
- ~
- ^^
Correct Answer - 2
>>
Explanation:
The ">>" operator is known as an insertion operator in C++.
3) There are the following statements that are below, which of them are correct about “endl” in C++?
- The "endl" is a manipulator in C++.
- The "endl" is used to print a new line on the standard output device.
- The "endl" is used to flush the output stream.
- The "endl" is a predefined structure.
Options:
- A and B
- B and C
- A, B, and C
- A, B, C, and D
Correct Answer - 3
A, B, and C
Explanation:
Statements A, B, and C are correct about endl in C++.
4) In C++, the cin and cout are?
- Predefined objects
- Predefined pointers
- Operators
- Keywords
Correct Answer - 1
Predefined objects.
Explanation:
The cin and cout are the predefined objects.
5) The insertion and exertion operators are overloaded in predefined "iostream" class?
- Yes
- No
Correct Answer - 1
Yes
Explanation:
Yes, the insertion and exertion operators are overloaded in predefined iostream class.
6) What is the correct output of the given code snippets?
#include <iostream>
int main()
{
std::cout<<"Hello world";
return 0;
}
Options:
- Compilation error
- Hello world
- Runtime Error
- Linker error
Correct Answer - 2
Hello world
Explanation:
The above code will print "Hello World" on the console screen.
7) What is the correct output of the given code snippets?
#include <iostream>
int main()
{
cout>>"ABC" <<" " <<"XYZ";
return 0;
}
Options:
- Compilation error
- ABC XYX
- Runtime Error
- Linker error
Correct Answer - 1
Compilation error
Explanation:
The above code will generate a compilation error because we cannot use exertion (>>) operator with cout.
8) What is the correct output of the given code snippets?
#include <iostream>
using namespace std;
int main()
{
cout<<("ABC")<<(" ")<<("XYZ");
return 0;
}
Options:
- Compilation error
- ABC XYX
- Runtime Error
- Linker error
Correct Answer - 2
ABC XYX
Explanation:
The above code will print "ABC XYZ" on the console screen.
9) What is the correct output of the given code snippets?
#include <iostream>
using namespace std;
int main()
{
cout<<("ABC"<<" "<<"XYZ");
return 0;
}
Options:
- Compilation error
- Hello world
- Runtime Error
- Linker error
Correct Answer - 1
Compilation error
Explanation:
The above code will generate syntax error.
10) What is the correct output of the given code snippets?
#include <iostream>
using namespace std;
int main()
{
int ret = 0;
ret = cout<<"ABC";
cout<<"ret: "<<ret;
return 0;
}
Options:
- Compilation error
- Hello world
- Runtime Error
- Linker error
Correct Answer - 1
Compilation error
Explanation:
The above code will generate a syntax error.
11) What is the correct output of the given code snippets?
#include <iostream>
using namespace std;
int main()
{
cout.operator<<("hello");
return 0;
}
Options:
- hello
- A hexadecimal address
- Runtime Error
- Linker error
Correct Answer - 2
A hexadecimal address
Explanation:
The above code will print a hexadecimal number on the console screen.
12) What is the correct output of the given code snippets?
#include <iostream>
using namespace std;
int main()
{
cout.operator<string><<("hello");
return 0;
}
Options:
- hello
- Compiler error
- Runtime Error
- Linker error
Correct Answer - 2
compiler error
Explanation:
The above code will generate syntax errors.