Increment And Decrement(C++ Programming ) Questions and Answers
Explanation:-
Answer: Option B. -> call by referenceNone.
Explanation:-
Answer: Option A. -> Preincrement is faster than postincrement.Because preincrement take one byte instruction & post increment takes two byte instruction
Question 3.
What is the output of this program?
1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int num1 = 5;
6.
int num2 = 3;
7.
int num3 = 2;
8.
num1 = num2++;
9.
num2 = --num3;
10.
cout
- 532
- 235
- 235
- 311
Explanation:-
Answer: Option D. -> 311In this program, We are preincrementing and postincrementing the operands and saving it.
Output:
$ g++ incre5.cpp
$ a.out
311
Question 4.
What is the output of this program?
1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int x = 5, y = 5, z;
6.
x = ++x; y = --y;
7.
z = x + ++x;
8.
cout
- 11
- 12
- 13
- 14
Explanation:-
Answer: Option D. -> 14In this program, we are adding the x value after preincrementing two times.
Output:
$ g++ incre4.cpp
$ a.out
14
Question 5.
What is the output of this program?
1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int x = 5, y = 5, z;
6.
x = ++x; y = --y;
7.
z = x++ + y--;
8.
cout << z;
9.
return 0;
10.
}
- 10
- 11
- 9
- 12
Explanation:-
Answer: Option A. -> 10In 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
Question 6.
What is the output of this program?
1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int x = 5, y = 5;
6.
cout
- 55
- 64
- 46
- 45
Explanation:-
Answer: Option B. -> 64The values will be preincemented and predecremented, So it will print as 64.
Output:
$ g++ incre2.cpp
$ a.out
64
Explanation:-
Answer: Option B. -> 2There are two types of increment/decrement. They are postfix and prefix.
Question 8.
What is the output of this program?
1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
int a = 21;
6.
int c ;
7.
c = a++;
8.
cout
- 21
- 22
- 23
- 20
Explanation:-
Answer: Option A. -> 21Explanation:value of 'a' will be stored in c and then only it will be incremented.
Output:
$ g++ incre.cpp
$ a.out
21
Explanation:-
Answer: Option A. -> Increment operator ++ adds 1 to its operandNone.
Explanation:-
Answer: Option C. -> both a & bNone.