Classes And Objects In C Plus Plus - Study Mode
[#146] What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
class B
{
int b
public:
B(int i){
b = i
}
}
class C
{
B b
public:
C(int i){
b = B(i)
}
friend void show()
}
void show()
{
C c(10)
cout<<"value of b is: "<<c.b.b<<endl
}
int main(int argc, char const *argv[])
{
show()
return 0
}
Correct Answer
(C) error
[#147] What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
int main ()
{
string str ("nobody does like this")
string key ("nobody")
size_t f
f = str.rfind(key)
if (f != string::npos)
str.replace (f, key.length(), "everybody")
cout << str << endl
return 0
}
Correct Answer
(D) everybody does like this
[#148] What is the correct syntax of accessing a static member of a Class? ---------------------------
Example class:
class A
{
public:
static int value
}
---------------------------
Correct Answer
(B) A::value
[#149] What will be the output of the following C++ code? #include <iostream>
using namespace std
class myclass
{
public:
int i
myclass *operator->()
{return this
}
}
int main()
{
myclass ob
ob->i = 10
cout << ob.i << " " << ob->i
return 0
}
Correct Answer
(A) 10 10
[#150] What happens when objects s1 and s2 are added? string s1 = "Hello"
string s2 = "World"
string s3 = (s1+s2).substr(5)
Correct Answer
(C) The statements runs perfectly