C Plus Plus Miscellaneous - Study Mode

[#886] What will be the output of the following C++ code? #include <iostream>
using namespace std
class bowl
{
public:
int apples
int oranges
}
int count_fruit(bowl * begin, bowl * end, int bowl :: *fruit)
{
int count = 0
for (bowl * iterator = begin
iterator != end
++ iterator)
count += iterator ->* fruit
return count
}
int main()
{
bowl bowls[2] = {{ 1, 2 },{ 3, 5 }}
cout << "I have " << count_fruit(bowls, bowls + 2, & bowl :: apples) << " apples
"
cout << "I have " << count_fruit(bowls, bowls + 2, & bowl :: oranges) << " oranges
"
return 0
}
Correct Answer

(A) I have 4 apples I have 7 oranges

[#887] What will be the output of the following C++ code? #include <iostream>
#include <Valarray>
using namespace std
int main()
{
Valarray<int> varr = { 10, 2, 20, 1, 30 }
for (int &x: varr) cout << x << " "
cout<<endl
varr = varr.apply([](int x){return x+=5
})
for (int &x: varr) cout << x << " "
return 0
}
Correct Answer

(A) 10 2 20 1 30 15 7 25 6 35

[#888] What will be the output of the following C++ code? #include <iostream>
using namespace std
int main()
{
int n = 15
for (
)
cout << n
return 0
}
Correct Answer

(C) infinite times of printing n

[#889] What will be the output of the following C++ code? #include<iostream>
#include<any>
using namespace std
int main()
{
float val = 5.5
any var(val)
cout<<var.type().name()<<endl
return 0
}
Correct Answer

(A) f

[#890] What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
int main ()
{
string mys
char mya[20]= "Hello world"
mys = mya
cout << mys << '
'
return 0
}
Correct Answer

(A) Hello world