C++ programming questions and answers focuses on “Increment and Decrement”. One shall practice these questions to improve their C++ programming skills needed for various interviews (campus interviews, walk-in interviews, company interviews, entrance exams and other competitive exams. C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ programming questions come with the detailed explanation of the answers which helps in better understanding of C++ concepts.
C++ programming Multiple Choice Questions & Answers focuses on “Increment and Decrement” along with answers, explanations and/or solutions:
Q 1. Which operator works only with integer variables?
A. increment
B. decrement
C. binary operator
D. both increment & decrement
Show Answer
Answer:-D. both increment & decrementExplanation
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.Q 2. How many types are there in increment/decrement operator?
A. 1
B. 2
C. 3
D. 4
Show Answer
Answer:-B. 2Explanation
There are two types of increment/decrement. They are postfix and prefix.Q 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
Show Answer
Answer:-A. Increment operator ++ adds 1 to its operandExplanation
Increment operator are used to increase the values of any integer variable by 1.Q 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. 10
B. 12
C. 19
D. 21
Show Answer
Answer:-D. 21Explanation
value of ‘a’ will be stored in c and then only it will be incremented. Output: $ g++ incre.cpp $ a.out 21Q 5. What will be the output of the following C++ code?
A. 45
B. 55
C. 60
D. 64
Show Answer
Answer:-D. 64Explanation
The values will be pre increment and pre decrement, So it will print as 64. Output: $ g++ incre2.cpp $ a.out 64Q 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. 12
D. 16
Show Answer
Answer:-A. 10Explanation
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 10Q 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
Show Answer
Answer:-D. 14Explanation
In this program, we are adding the x value after pre incrementing two times. Output: $ g++ incre4.cpp $ a.out 14Q 8. What will be the output of the following C++ code?
A. 311
B. 315
C. 316
D. 430
Show Answer
Answer:-A. 311Explanation
In this program, We are pre increment and post incrementing the operands and saving it. Output: $ g++ incre5.cpp $ a.out 311Q 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
Show Answer
Answer:-A. Pre Increment is faster than post-incrementExplanation
Because Pre Increment take one-byte instruction & post increment takes two-byte instruction.Q 10. Which concepts does the Pre Increment use?
A. call by value
B. queue
C. call by reference
D. call by name
Leave a Reply