C Plus Plus Miscellaneous - Study Mode
[#791] What will be the output of the following C++ code? #include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
srand (time(NULL))
printf ("Random number: %d
", rand() % 100)
srand (1)
return 0
}
Correct Answer
(D) Any number from 0 to 99
[#792] What will be the output of the following C++ code? #include <iostream>
#include <string>
using namespace std
int main()
{
cout<<is_array<int>::value
cout<<is_array<char[10]>::value
cout<<is_array<string>::value
return 0
}
Correct Answer
(A) 010
[#793] What will be the output of the following C++ code? #include <iostream>
#include <exception>
using namespace std
void myunexpected ()
{
cout << "unexpected handler called
"
throw
}
void myfunction () throw (int,bad_exception)
{
throw 'x'
}
int main (void)
{
set_unexpected (myunexpected)
try
{
myfunction()
}
catch (int)
{
cout << "caught int
"
}
catch (bad_exception be)
{
cout << "caught bad_exception
"
}
catch (...)
{
cout << "caught other exception
"
}
return 0
}
Correct Answer
(D) both unexpected handler called & caught bad_exception
[#794] What will be the output of the following C++ code? #include <iostream>
using namespace std
template<typename type>
class TestVirt
{
public:
virtual type TestFunct(type Var1)
{
return Var1 * 2
}
}
int main()
{
TestVirt<int> Var1
cout << Var1.TestFunct(100) << endl
return 0
}
Correct Answer
(B) 200
[#795] What will be the output of the following C++ code? #include <iostream>
using namespace std
class stu
{
protected:
int rno
public:
void get_no(int a)
{
rno = a
}
void put_no(void)
{
}
}
class test:public stu
{
protected:
float part1,part2
public:
void get_mark(float x, float y)
{
part1 = x
part2 = y
}
void put_marks()
{
}
}
class sports
{
protected:
float score
public:
void getscore(float s)
{
score = s
}
void putscore(void)
{
}
}
class result: public test, public sports
{
float total
public:
void display(void)
}
void result::display(void)
{
total = part1 + part2 + score
put_no()
put_marks()
putscore()
cout << "Total Score=" << total << "
"
}
int main()
{
result stu
stu.get_no(123)
stu.get_mark(27.5, 33.0)
stu.getscore(6.0)
stu.display()
return 0
}
Correct Answer
(A) 66.5