Classes And Objects In C Plus Plus - Study Mode

[#141] What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std

class A
{
mutable int a

public:
int assign(int i) const {
a = i

}
int return_value() const {
return a

}

}

int main(int argc, char const *argv[])
{
A obj

obj.assign(5)

cout<<obj.return_value()

}
Correct Answer

(A) 5

[#142] What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std

int main ()
{
string str ("helloworld.")

cout << str.substr(3).substr(4) << endl

return 0

}
Correct Answer

(B) rld.

[#143] What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std

int main(int argc, char const *argv[])
{
char str[] = "Hello World"

cout<<str[0]

return 0

}
Correct Answer

(A) H

[#144] What will be the output of the following C++ code? #include <iostream>
using namespace std

int main()
{
int a = 0

int b = 10

if ( a && b )
{
cout << "true"<< endl

}
else
{
cout << "false"<< endl

}
return 0

}
Correct Answer

(B) false

[#145] What will be the output of the following C++ code? #include <iostream>
using namespace std

int main()
{
typedef int num

num a = 10, b = 15

num c = a + b + a - b

cout << c

return 0

}
Correct Answer

(A) 20