Quiz on Operators in C++
Any programming language is built on operators. Without operators, C/C++ would not be as functional. Operators are described as symbols, which help us to perform a variety of computational operations on them. Now, let’s take a look at the quiz to learn more about operators in c++. Good luck!
0 of 15 Questions completed Questions: You have already completed the quiz before. Hence you can not start it again. Quiz is loading… You must sign in or sign up to start the quiz. You must first complete the following: 0 of 15 Questions answered correctly Your time: Time has elapsed You have reached 0 of 0 point(s), (0) Earned Point(s): 0 of 0, (0) (i)++ (increment) (ii) ?:(conditional operator) (iii) &&(logical AND) (iv) <<= (Bitwise shift left) #include <iostream> using namespace std; int main() { int res; res = 20*30/5+6; cout<<res; return 0; } #include<iostream> using namespace std; int main() { int a,b,c,d,i; a=40; b=50; c=a,b; d=(a,b); i = (d++, d + 100, 50 + d); cout << i; return 0; } #include <iostream> using namespace std; int main () { int a, b; a = 10; b = ++a * a++; cout <<“a=”<<a<<“b=”<< b<<” “; b = a++ * ++a; cout <<“new a=”<< a<<“new b=”<< b; return 0; } #include <iostream> using namespace std; int main() { int val1, val2, c; val1=40; val2=50; val1>val2?cout<<“value1 is greater than value2″<<endl:cout<<“value2 is greater than value1″<<endl; c= (val1> val2)?val1:val2; cout << c; return 0; } #include <iostream> using namespace std; int main() { float a; float b=65.564545; int c ; double d=65.567634; c = (int) b; a = (float)d; cout << c <<” “<< a; return 0; } #include <iostream> using namespace std; class Rect { private: int length; public: Rect(int l):length(l) {} void fun() const { ( const_cast <Rect*> (this) )->length = 20; } int getLength() { return length; } }; int main(void) { Rect r(10); cout << “Old Length: ” << r.getLength() << endl; r.fun(); cout << “New Length: ” << r.getLength() << endl; return 0; } #include <iostream.h> using namespace std; int function(int* ptr) { return (*ptr + 50); } int main() { const int value = 20; const int *pointer = &value; int *ptr1 = const_cast <int *>(pointer); cout << function(ptr1); return 0; } #include <iostream> using namespace std; int main() { double value= 55.5; int c = value; int d = static_cast<int>(value); cout << d++ + ++d; } #include <iostream> using namespace std; int main() { int i = 20; int size = sizeof(++i); cout << ” Size of i = ” << size<<endl; i=i,++i; cout << ” Value of i = ” << i; return 0; } #include <iostream> using namespace std; int main() { int a = 60, b = 50, c=10; if (a > b && a >c) { cout << “a is greater than b and c\n”; } else if(b>a && b>c) { cout << “b is greater than a and c\n”; } else if(c>a&& c>b) { cout<<“c is greater than a and b\n”; } else if(a==b && a==c) { cout<<“a is equal to b and c”; } else if(a==b) { cout<<“a is equal to b”; } else if(a==c) { cout<<“a is equal to c”; } else if(b==c) { cout<<“b is equal to c”; } return 0; } class Rect { int *ptr; public: Rect (int length = 0) { ptr = new int(length); } void setValue (int l) { *ptr = l; } void display() { cout << *ptr << endl; } }; int main() { Rect r(50); Rect r1; r1 = r; r.setValue(30); r1.display(); return 0; } #include<iostream> using namespace std; class Rect { int *ptr; public: Rect (int length = 0) { ptr = new int(length); } void setValue (int l) { *ptr = l; } void display() { cout << *ptr << endl; } Rect & operator = (const Rect &r); }; Rect & Rect::operator = (const Rect &r) { if(this != &r) *ptr = *(r.ptr); return *this; } int main() { Rect r(50); Rect r1; r1 = r; r.setValue(30); r1.display(); return 0; } #include <iostream> using namespace std; int main() { int a = 20, b = 30; bool res = ((a != b) && cout << “QuizOrbit\n”); if(res==1) cout<<“TRUE”; else cout<<“FALSE”; return 0; } #include <iostream> using namespace std; int main() { int a = 20, b = 30, c = 50, d = 40; if (a > b && a > c && a>d) cout << “A is greater than b,c and d”<<endl; else cout << “Logical And Condition Fails”<<endl; if (a > b || a>c || a>d) cout << “Either a is greater than b, c or d “<<endl; else cout << “Neither a is greater than b, c nor d”<<endl; return 0; } Quiz Summary
Information
Results
Results
0 Essay(s) Pending (Possible Point(s): 0) Categories
1. Question
2. Question
3. Question
4. Question
5. Question
6. Question
7. Question
8. Question
9. Question
10. Question
11. Question
12. Question
13. Question
14. Question
15. Question
Summary
The purpose of this quiz was to test your knowledge of operators in C++. Understand each concept thoroughly before moving forward. Let us know if you have any questions in the comments. Have a great time learning!