Here is a listing of C++ programming Multiple Choice Questions & Answers focuses on “Increment and Decrement” along with answers, explanations and/or solutions:
1. Which operator works only with integer variables?
a) increment
b) decrement
c) both increment & decrement
d) binary operator
View Answer
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
View Answer
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
View Answer
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 <stdio.h>
#include<iostream>
using namespace std;
int main()
{
int a = 21;
int c ;
c = a++;
cout << c;
return 0;
}
a) 21
b) 22
c) 23
d) 20
View Answer
Explanation: value of ‘a’ will be stored in c and then only it will be incremented.
Output:
$ g++ incre.cpp $ a.out 21
5. What will be the output of the following C++ code?
#include <stdio.h>
#include<iostream>
using namespace std;
int main()
{
int x = 5, y = 5;
cout << ++x << --y << endl;
return 0;
}
a) 55
b) 64
c) 46
d) 45
View Answer
Explanation: The values will be pre increment and pre decrement, So it will print as 64.
Output:
$ g++ incre2.cpp $ a.out 64
6. What will be the output of the following C++ code?
#include <stdio.h>
#include<iostream>
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
View Answer
Explanation: In this program, the increment and decrement of evaluation of z will not be accounted because they are post.
Output:
$ g++ incre3.cpp $ a.out 10
7. What will be the output of the following C++ code?
#include <stdio.h>
#include<iostream>
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
View Answer
Explanation: In this program, we are adding the x value after pre incrementing two times.
Output:
$ g++ incre4.cpp $ a.out 14
8. What will be the output of the following C++ code?
#include <stdio.h>
#include<iostream>
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
View Answer
Explanation: In this program, We are pre increment and post incrementing the operands and saving it.
Output:
$ g++ incre5.cpp $ a.out 311
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
View Answer
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
View Answer
Explanation: call by reference because the changes are reflected back to the same memory cells/variables.
Sanfoundry Global Education & Learning Series – C++ Programming Language.
To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Practice Programming MCQs
- Apply for C++ Internship
- Practice Computer Science MCQs
- Apply for Computer Science Internship
- Check Programming Books