OOP Using C++ — MCQ Practice

Hindi aur English dono mein practice karo — click karo answer check karne ke liye

📚 107 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
107 questions
76
EN + हिं
GB What is the output: class A{int x=0; public: void inc(){x++;} int get()const{return x;} A operator+(const A& o)const{A r; r.x=x+o.x; return r;}}; A a,b; a.inc();a.inc(); b.inc(); cout<<(a+b).get();
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: void inc(){x++;} int get()const{return x;} A ऑपरेटर+(const A& o)const{A r; r.x=x+o.x; वापसी आर;}}; ए ए, बी; a.inc();a.inc(); b.inc(); अदालत
A
3 3
B
2 2
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.x=2, b.x=1. (a+b).x=3. Output: 3.
व्याख्या (हिन्दी) a.x=2, b.x=1. (ए+बी).एक्स=3. आउटपुट: 3.
77
EN + हिं
GB What is the output: class A{int x=5; public:int get()const{return x;} void set(int v){if(v>0)x=v;}}; A a; a.set(-3); cout<
IN आउटपुट क्या है: class A{int x=5; सार्वजनिक:int get()const{return x;} void set(int v){if(v>0)x=v;}}; ए ए; ए.सेट(-3); अदालत
A
57 57
B
55 55
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Rejected -3; 7 accepted. Output: 57.
व्याख्या (हिन्दी) अस्वीकृत -3; 7 स्वीकृत. आउटपुट: 57.
78
EN + हिं
GB What is the output: class A{int x; public:A(int v):x(v){} int get()const{return x;} A operator+(const A& o)const{return {x+o.x};}}; A a(3),b(4); A c=a+b; cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक:ए(int v):x(v){} int get()const{return x;} A ऑपरेटर+(const A& o)const{return {x+o.x};}}; ए ए(3),बी(4); ए सी=ए+बी; अदालत
A
7 7
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3+4=7. Output: 7.
व्याख्या (हिन्दी) 3+4=7. आउटपुट: 7.
79
EN + हिं
GB What is the output: class A{int x=0,y=0; public:void setX(int v){x=v;} void setY(int v){y=v;} int sum()const{return x+y;}}; A a; a.setX(3); a.setY(4); cout<
IN आउटपुट क्या है: class A{int x=0,y=0; सार्वजनिक:void setX(int v){x=v;} void setY(int v){y=v;} int sum()const{return x+y;}}; ए ए; ए.सेटएक्स(3); a.setY(4); अदालत
A
7 7
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3+4=7. Output: 7.
व्याख्या (हिन्दी) 3+4=7. आउटपुट: 7.
80
EN + हिं
GB What is the output: class A{vectorv; public:void add(int x){if(x>=0)v.push_back(x);} int max()const{return *max_element(v.begin(),v.end());}}; A a; a.add(-1);a.add(3);a.add(7);a.add(-2);a.add(5); cout<
IN आउटपुट क्या है: class A{vectorv; सार्वजनिक:शून्य जोड़ें(int x){if(x>=0)v.push_back(x);} int max()const{return *max_element(v.begin(),v.end());}}; ए ए; a.जोड़ें(-1);a.जोड़ें(3);a.जोड़ें(7);a.जोड़ें(-2);a.जोड़ें(5); अदालत
A
7 7
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Valid: 3,7,5. max=7. Output: 7.
व्याख्या (हिन्दी) मान्य: 3,7,5. अधिकतम=7. आउटपुट: 7.
81
EN + हिं
GB What is the output: class A{int x; public:A(int v):x(v){} int get()const{return x;} A& operator*=(int n){x*=n;return *this;}}; A a(3); a*=2; a*=3; cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक:ए(int v):x(v){} int get()const{return x;} A& ऑपरेटर*=(int n){x*=n;return *this;}}; ए ए(3); ए*=2; ए*=3; अदालत
A
18 18
B
6 6
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3*2=6; 6*3=18. Output: 18.
व्याख्या (हिन्दी) 3*2=6; 6*3=18. आउटपुट: 18.
82
EN + हिं
GB What is the output: class Safe{int arr[10]={0}; public:int& at(int i){if(i<0||i>=10)throw out_of_range("OOB");return arr[i];}}; Safe s; s.at(3)=42; cout<
IN आउटपुट क्या है: class Safe{int arr[10]={0}; public:int& at(int i){if(i=10)throw out_of_range("OOB");return arr[i];}}; सुरक्षित एस; s.at(3)=42; अदालत
A
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) at(3)=42. Output: 42.
व्याख्या (हिन्दी) at(3)=42. आउटपुट: 42.
83
EN + हिं
GB What is the output: class A{int x=0; public:int get()const{return x;} void reset(){x=0;} A& set(int v){x=v;return *this;}}; A a; cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक:int get()const{return x;} void रीसेट(){x=0;} A& set(int v){x=v;return *this;}}; ए ए; अदालत
A
50 50
B
55 55
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.set(5).get()=5; a.reset() (returns void); comma op; a.get()=0. Output: 50.
व्याख्या (हिन्दी) a.set(5).get()=5; a.reset() (शून्य रिटर्न); अल्पविराम सेशन; a.get()=0. आउटपुट: 50.
84
EN + हिं
GB What is the output: class A{int x; public:A(int v=0):x(v){} bool isValid()const{return x>=0&&x<=100;} void clip(){if(x<0)x=0;if(x>100)x=100;}}; A a(-5); a.clip(); cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक:A(int v=0):x(v){} bool isValid()const{return x>=0&&x
A
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) clip sets x=0. isValid()=1. Output: 1.
व्याख्या (हिन्दी) क्लिप सेट x=0. वैध()=1 है। आउटपुट: 1.
85
EN + हिं
GB What is the output: class A{int x=1,y=2,z=3; public:auto getAll()const{return make_tuple(x,y,z);}}; A a; auto [x,y,z]=a.getAll(); cout<
IN आउटपुट क्या है: class A{int x=1,y=2,z=3; सार्वजनिक:ऑटो getAll()const{return make_tuple(x,y,z);}}; ए ए; ऑटो [x,y,z]=a.getAll(); अदालत
A
6 6
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 1+2+3=6. Output: 6.
व्याख्या (हिन्दी) 1+2+3=6. आउटपुट: 6.
86
EN + हिं
GB What is the output: class A{int x=0; public:int get()const{return x;} void f(){x++;} void g(){f();f();f();}}; A a; a.g(); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक:int get()const{return x;} void f(){x++;} void g(){f();f();f();}}; ए ए; a.g(); अदालत
A
3 3
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) g() calls f() 3 times: x=3. Output: 3.
व्याख्या (हिन्दी) g() f() को 3 बार कॉल करता है: x=3। आउटपुट: 3.
87
EN + हिं
GB What is the output: class A{int n; public:A(int v):n(v){} auto begin(){return &n;} auto end(){return &n+1;}}; A a(42); for(int x:a) cout<
IN आउटपुट क्या है: class A{int n; सार्वजनिक:ए(int v):n(v){} ऑटो प्रारंभ(){रिटर्न &n;} ऑटो एंड(){रिटर्न &n+1;}}; ए ए(42); for(int x:a) कोउट
A
42 42
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Iterates single element 42. Output: 42.
व्याख्या (हिन्दी) एकल तत्व को पुनरावृत्त करता है 42. आउटपुट: 42.
88
EN + हिं
GB What is the output: class A{int x; public:A(int v):x(v){} int operator()(int y)const{return x*y;} int operator()(int y,int z)const{return x*(y+z);}}; A a(3); cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक:ए(int v):x(v){} int ऑपरेटर()(int y)const{रिटर्न x*y;} int ऑपरेटर()(int y,int z)const{रिटर्न x*(y+z);}}; ए ए(3); अदालत
A
1227 1227
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
12 27 12 27
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a(4)=3*4=12; a(4,5)=3*9=27. Output: 1227.
व्याख्या (हिन्दी) ए(4)=3*4=12; a(4,5)=3*9=27. आउटपुट: 1227.
89
EN + हिं
GB What is the output: class A{int x=0; public:A& inc(){x++;return *this;} A& mul(int n){x*=n;return *this;} int val()const{return x;}}; A a; cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक:A& inc(){x++;return *this;} A& mul(int n){x*=n;return *this;} int val()const{return x;}}; ए ए; अदालत
A
9 9
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 0+1+1+1=3; 3*3=9. Output: 9.
व्याख्या (हिन्दी) 0+1+1+1=3; 3*3=9. आउटपुट: 9.
90
EN + हिं
GB What is the output: class A{int x; public:explicit A(int v):x(v){} A operator-()const{return A(-x);} int get()const{return x;}}; A a(5); A b=-a; cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक:स्पष्ट A(int v):x(v){} A ऑपरेटर-()const{return A(-x);} int get()const{return x;}}; ए ए(5); ए बी=-ए; अदालत
A
-5 -5
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) -a: operator-() returns A(-5). b.get()=-5. Output: -5.
व्याख्या (हिन्दी) -ए: ऑपरेटर-() रिटर्न ए(-5)। बी.प्राप्त()=-5. आउटपुट:-5.
76–90 of 107