What will be the output of the following C++ code?
#include <iostream>
#include <cmath>
#include <list>
using namespace std;
bool same_integral_part (double first, double second)
{
return ( int(first) == int(second) );
}
struct is_near
{
bool operator() (double first, double second)
{
return (fabs(first - second) < 5.0);
}
};
int main ()
{
double mydoubles[] = { 12.15, 2.72, 73.0, 12.77, 3.14, 12.77, 73.35, 72.25, 15.3, 72.25 };
list<double> mylist (mydoubles, mydoubles + 10);
mylist.sort();
mylist.unique();
mylist.unique (same_integral_part);
mylist.unique (is_near());
for (list<double> :: iterator it = mylist.begin(); it != mylist.end(); ++it)
cout << ' ' << *it;
cout << '\n';
return 0;
}
#include <iostream>
#include <cmath>
#include <list>
using namespace std;
bool same_integral_part (double first, double second)
{
return ( int(first) == int(second) );
}
struct is_near
{
bool operator() (double first, double second)
{
return (fabs(first - second) < 5.0);
}
};
int main ()
{
double mydoubles[] = { 12.15, 2.72, 73.0, 12.77, 3.14, 12.77, 73.35, 72.25, 15.3, 72.25 };
list<double> mylist (mydoubles, mydoubles + 10);
mylist.sort();
mylist.unique();
mylist.unique (same_integral_part);
mylist.unique (is_near());
for (list<double> :: iterator it = mylist.begin(); it != mylist.end(); ++it)
cout << ' ' << *it;
cout << '\n';
return 0;
}A. 2.72 12.15 72.25
B. 12.15 73.0 12.77
C. 73.35
D. 74.45
Answer: Option A
What does the 'sizeof' operator return in C++?
A. Size of a data type in bits
B. Size of a data type in bytes
C. Size of a variable in bytes
D. Size of a variable in bits
What is the purpose of the 'static' keyword in C++?
A. To declare a variable with dynamic storage duration
B. To declare a constant
C. To declare a variable with external linkage
D. To declare a variable with static storage duration
What is the difference between '++i' and 'i++' in C++?
A. None of the above
B. They both have the same effect
C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it
D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it

Join The Discussion