Question 21
EasyIn C++, which operator accesses a member through a pointer to an object?
- A.
&
- B.
.
- C.
->
- D.
::
Sign up free to see the answer and a step-by-step explanation.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Object-Oriented Programming
In C++, which operator accesses a member through a pointer to an object?
&
.
->
::
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class Counter:
def __init__(self):
self.n = 0
def inc(self):
self.n += 1
c = Counter()
c.inc()
c.inc()
print(c.n)
2
1
Error
0
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class Box:
def __init__(self, v):
self.v = v
a = Box(1)
b = Box(2)
a.v = 5
print(a.v, b.v)
5 2
1 2
5 5
2 5
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class P:
pass
p = P()
q = p
q.x = 10
print(p.x)
0
10
Error
None
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
#include <iostream>
using namespace std;
class Point {
public:
int x, y;
};
int main() {
Point p;
p.x = 3;
p.y = 4;
cout << p.x * p.y;
}
12
34
Compilation error
7
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
#include <iostream>
using namespace std;
class A {
public:
int v;
};
int main() {
A a;
a.v = 1;
A b = a;
b.v = 7;
cout << a.v << b.v;
}
11
71
77
17
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class Dog:
sound = "Woof"
d = Dog()
print(d.sound)
Woof
Error
sound
None
Sign up free to see the answer and a step-by-step explanation.
What is a static member of a class?
A member created for each object
A member that is private
A member that can never change
A member shared by all objects of the class, not owned by any one object
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
#include <iostream>
using namespace std;
class Box {
public:
static int count;
Box() { count++; }
};
int Box::count = 0;
int main() {
Box a, b, c;
cout << Box::count;
return 0;
}
3
0
1
Error
Sign up free to see the answer and a step-by-step explanation.
What is the output of this code?
class Car:
def __init__(self, speed):
self.speed = speed
a = Car(10)
b = Car(20)
print(a.speed, b.speed)
20 20
10 20
20 10
10 10
Sign up free to see the answer and a step-by-step explanation.