How many types of comments are there in C++?
Which of the following is not a valid file mode?
What is the only function all C programs must contain?
What will be the output of the following C++ code?
What is the output of the following program?
struct time
{
int H;
int M;
int S;
} time1;
int main()
{
struct time *p;
p = &time1;
p->H = 4;
p->M = 22;
p->S = 12;
printf("%d %d %d", p->H, p->M, p->S);
}
#include <iostream>
using namespace std;
int main () {
int x = 10;
int y = 20;
{
int x; // ok, inner scope.
x = 50; // sets value to inner x
y = 50; // sets value to (outer) y
cout << "x: " << x << '\n';
}
cout << "x: " << x << '\n';
return 0;
}
What will be the output of the following C++ code?
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream outfile("test.txt");
for (int n = 0; n < 100; n++) {
outfile << n;
outfile.flush();
}
cout << "Done";
outfile.close();
return 0;
}
What is the output of the following C++ code?
class complex{
double re;
double im;
public:
complex() : re(0),im(0) {}
complex(double n) { re=n,im=n;};
complex(int m,int n) { re=m,im=n;}
void print() { cout<<re; cout<<im;}
};
void main(){
complex c3;
double i=5;
c3 = i;
c3.print();
}
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main ()
{
int first[] = {5, 10, 15, 20, 25};
int second[] = {50, 40, 30, 20, 10};
vector<int> v(10);
vector<int> :: iterator it;
sort (first, first + 5);
sort (second, second + 5);
it = set_union (first, first + 5, second, second + 5, v.begin());
cout << int(it - v.begin());
return 0;
}
What will be the output of the following C++ code?
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool myfunction (int i, int j) { return (i < j); }
int main()
{
int myints[] = {9, 8, 7, 6, 5};
vector<int> myvector(myints, myints + 5);
partial_sort(myvector.begin(), myvector.begin() + 3, myvector.end());
partial_sort(myvector.begin(), myvector.begin() + 2, myvector.end(), myfunction);
for (vector<int>::iterator it = myvector.begin(); it != myvector.end(); ++it)
cout << ' ' << *it;
return 0;
}