1. Which operator works only with integer variables?
A. increment
B. decrement
C. both increment & decrement
D. binary operator
Answer: C
Explanation:
Because increment and decrement operator increases increasing and decreasing values of values and no such things define in strings so cannot be used with strings. Also they cannot be used with floats and doubles because there is no way to fix how much the value should be increased or decreased if increment or decrement operator is applied on such variables. That’s why both these operators only works with integer values.
2. How many types are there in increment/decrement operator?
A. 1
B. 2
C. 3
D. 4
Answer: B
Explanation:
There are two types of increment/decrement. They are postfix and prefix.
3. Pick out the correct statement.
A. Increment operator ++ adds 1 to its operand
B. Increment operator ++ adds 2 to its operand
C. Decrement operator ++ subtracts 1 to its operand
D. Decrement operator ++ subtracts 3 to its operand
Answer: A
Explanation:
Increment operator are used to increase the values of any integer variable by 1.
4. What will be the output of the following C++ code?
#include
#include
using namespace std;
int main()
{
int a = 21;
int c ;
c = a++;
cout << c;
return 0;
}
A. 21
B. 22
C. 23
D. 20
Answer: A
Explanation:
value of ‘a’ will be stored in c and then only it will be incremented.
5. What will be the output of the following C++ code?
#include
#include
using namespace std;
int main()
{
int x = 5, y = 5;
cout << ++x << --y << endl;
return 0;
}
A. 55
B. 64
C. 46
D. 45
Answer: A
Explanation:
In this program, we are copying the memory location of x into p and then printing the value in the address.
6. What will be the output of the following C++ code?
#include
#include
using namespace std;
int main()
{
int x = 5, y = 5, z;
x = ++x; y = --y;
z = x++ + y--;
cout << z;
return 0;
}
A. 10
B. 11
C. 9
D. 12
Answer: A
Explanation:
In this program, the increment and decrement of evaluation of z will not be accounted because they are post.
7. What will be the output of the following C++ code?
#include
#include
using namespace std;
int main()
{
int x = 5, y = 5, z;
x = ++x; y = --y;
z = x + ++x;
cout << z;
return 0;
}
A. 11
B. 12
C. 13
D. 14
Answer: D
Explanation:
In this program, we are adding the x value after pre incrementing two times.
8. What will be the output of the following C++ code?
#include
#include
using namespace std;
int main()
{
int num1 = 5;
int num2 = 3;
int num3 = 2;
num1 = num2++;
num2 = --num3;
cout << num1 << num2 << num3;
return 0;
}
A. 532
B. 235
C. 312
D. 311
Answer: D
Explanation:
In this program, We are pre increment and post incrementing the operands and saving it.
9. Pick out the correct statement.
A. Pre Increment is faster than post-increment
B. post-increment is faster than Pre Increment
C. pre increment is slower than post-increment
D. pre decrement is slower than post-increment
Answer: A
Explanation:
Because Pre Increment take one-byte instruction & post increment takes two-byte instruction.
10. Which concepts does the Pre Increment use?
A. call by value
B. call by reference
C. queue
D. call by name
Answer: B
Explanation:
call by reference because the changes are reflected back to the same memory cells/variables