Programming
Programming
int main()
{
int i = 0, j = i++, k = --i;
if (i > 0)
j++;
else
k++;
if(k == 0)
i++;
else if (k > 0)
k--;
else
k++;
cout << i * j * k;
}
ANSWER: C
Q2
What is the output of the following snippet?
#include <iostream>
int main()
{
int i = 0, j = i++, k = --i;
if (i > 0)
j++;
else
k++;
if(k == 0)
i++;
else if (k > 0)
k--;
else
k++;
cout << i * j * k;
}
ANSWER: C
Q3
What is the output of the following snippet?
#include <vector>
int main()
{
vector<int> t = { 8, 4, 3, 2, 1 };
int i;
ANSWER: D
Q4
What is the output of the following snippet?
#include <iostream>
#include <vector>
int main ()
{
vector<int> t= { 5, 6, 7 };
cout << fun (&t[1]);
cout << t [0];
}
ANSWER: C
Q5
What is the output of the following snippet?
#include <iostream>
int main()
{
cout<< fun (fun(1., 2.), fun(2., 1.));
}
ANSWER: B
Q6
What is the output of the following snippet?
include <iostream>
int main()
{
int *val = new int;
ANSWER: D
Q7
What is the output of the following snippet?
#include <iostream>
#include <vector>
int main()
{
vector<int> t = {0, 1, 2, 3};
Q8
What is the output of the following snippet?
#include <iostream>
int f1(int a)
{
return ++a;
}
int main()
{
int value = 2;
Q9
What is the output of the following snippet?
#include <iostream>
void Void(int n)
{
float v = n;
v = Float (v);
cout << v;
}
int main ()
{
Void(1);
}
ANSWER: C
Q10
What is the output of the following snippet?
#include <iostream>
int main()
{
cout << fun (1L) << fun ('x') << fun (2e0f);
}
ASNWER: C
Q11
What is the output of the following snippet?
#include <iostream>
#include<vector>
int main()
{
vector<int> tab = { 1, 2, 4 };
int *p1 = &tab[0], *p2 = p1 +2;
ANSWER: A
Q12
What is the output of the following snippet?
#include <iostream>
int fun(long a)
{
return a / a;
}
int fun(int a)
{
return 2 * a;
}
int main() {
cout << fun(1000000000l) << fun (1l) << fun (1.f);
}
ANSWER: A
Q13
What is the output of the following snippet?
#include <iostream>
struct s {
float *f;
};
int main()
{
s *ss = new s;
make(ss) ;
cout << * (*ss) . f;
delete ss->f;
delete ss;
}
ANSWER: D
Q14
What is the output of the following snippet?
#include <iostream>
#include <string>
int main ()
{
string name = "x";
cout << fun(name, name);
cout << name;
}
ANSWER: A
Q15
What is the output of the following snippet?
#include <iostream>
#include <string>
int main ()
{
string name = "a";
cout << fun (name);
cout << name;
}
ANSWER: C
Q16
What is the output of the following snippet?
#include <iostream>
namespace s1 {
int A = 1;
}
namespace s2 {
int A = 2 ;
}
int main ()
{
{ using namespace s1 ;
s2 :: A + 1;
}
using namespace s2;
s1 :: A = A + 1;
}
cout << S1 :: A<< S2 :: A;
}
ANSWER: D
Q17
What is the output of the following snippet?
#include <iostream>
int main()
{
int *it [3];
}
cout << it [2] [2];
for (int i = 0; i < 3; i++)
delete [] it [i];
}
ANSWER: D
Q18
What is the output of the following snippet?
#include <iostream>
#include <string>
#include <vector>
int main()
{
vector<string> t = { "alpha", "beta", "gamma"} ;
int *cnt = new int [3], *p = &cnt[0];
ANSWER: B
Q19
What is the output of the following snippet?
#include <iostream>
int main()
{
short s = 1;
int i = 2;
float f = 4.4;
double d = 6.6;
Q20
What is the output of the following snipet?
#include <iostream>
#include <string>
int main()
{
string s1 = "aleph";
string s2 = "alpha";
string s;
s1.swap(s2);
s2.swap(s);
s.swap (s2);
cout << s2;
}
ANSWER: D