0% found this document useful (0 votes)
21 views21 pages

Programming

Uploaded by

AL-JAMEE DERON
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views21 pages

Programming

Uploaded by

AL-JAMEE DERON
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Q1

What is the output of the following snippet?


#include <iostream>

using namespace std;

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>

using namespace std;

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>

using namespace std;

int main()
{
vector<int> t = { 8, 4, 3, 2, 1 };
int i;

for (i = t [4]; i < t[3]; i++)


t[i - 1] = - t[3];
cout << i;
}

ANSWER: D

Q4
What is the output of the following snippet?
#include <iostream>
#include <vector>

using namespace std;

int fun (int * t)


{
t [0] += t[1];
return t [0];
}

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>

using namespace std;

int fun ( float a, float b)


{
return a / b;
}

int main()
{
cout<< fun (fun(1., 2.), fun(2., 1.));
}

ANSWER: B
Q6
What is the output of the following snippet?
include <iostream>

using namespace std;

int main()
{
int *val = new int;

*val = sizeof (val) / sizeof (int *);


int *tab = new int [*val];
tab[0] = *val;
delete val;
cout << *tab;
delete[] tab;
}

ANSWER: D

Q7
What is the output of the following snippet?
#include <iostream>
#include <vector>

using namespace std;

int f1(int *a)


{
return *a + 1;
}

int *f2(int *a)


{
return a + 1;
}

int *f3(int &a)


{
return &a + 1;
}

int main()
{
vector<int> t = {0, 1, 2, 3};

cout << f1(f3(*f2(t. data())));


}
ANSWER: B

Q8
What is the output of the following snippet?
#include <iostream>

using namespace std;

int f1(int a)
{
return ++a;
}

int f2(int &a)


{
return ++a;
}

int f3(int *a)


{
return *a + 1;
}

int main()
{
int value = 2;

cout << f1(value);


cout << f2(value);
cout << f3(&value);
}
ANSWER: C

Q9
What is the output of the following snippet?
#include <iostream>

using namespace std;

float Float (float x)


{
return 2 * x / (.5 * x);
}

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>

using namespace std;

int fun (long a, long b = 1)


{
return a << b;
}

int fun(int a, char b = 'z')


{
return b - a;
}

int fun(float a, float b = 0)


{
return a * b;
}

int main()
{
cout << fun (1L) << fun ('x') << fun (2e0f);
}

ASNWER: C

Q11
What is the output of the following snippet?
#include <iostream>
#include<vector>

using namespace std;

int main()
{
vector<int> tab = { 1, 2, 4 };
int *p1 = &tab[0], *p2 = p1 +2;

tab[1] = p2[-1] + *p1;


cout << tab[1];
}

ANSWER: A

Q12
What is the output of the following snippet?
#include <iostream>

using namespace std;

int fun(long a)
{
return a / a;
}

int fun(int a)
{
return 2 * a;
}

int fun(double a = 3.0)


{
return a;
}

int main() {
cout << fun(1000000000l) << fun (1l) << fun (1.f);
}

ANSWER: A

Q13
What is the output of the following snippet?
#include <iostream>

using namespace std;

struct s {
float *f;
};

void make (s *p, float x = 10)


{
float *f = new float;
*f = sizeof (*f) / sizeof (float) * 10;
p->f = 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>

using namespace std;

string fun (string &t, string s = "" , int r = 1)


{
while (--r)
s += s;
t = t + s;
return s;
}

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>

using namespace std;

string fun (string t, string s = "x", int r = 1)


{
while (--r)
s += s;
t = t + s;
return s;
}

int main ()
{
string name = "a";
cout << fun (name);
cout << name;
}

ANSWER: C

Q16
What is the output of the following snippet?
#include <iostream>

using namespace std;

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>

using namespace std;

int main()
{
int *it [3];

for (int i = 0; i < 3; i++) {


it [i] = new int [i + 1];
for (int j = 0; j < i + 1 ; j++)
it [i] [j] = 10 * i + j;

}
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>

using namespace std;

int main()
{
vector<string> t = { "alpha", "beta", "gamma"} ;
int *cnt = new int [3], *p = &cnt[0];

for (int i = 0; i < t. size () ; i++)


*p++ =t[i] . length ();
cout << cnt [0] << cnt [1] << cnt[2];
delete [] cnt;
}

ANSWER: B

Q19
What is the output of the following snippet?
#include <iostream>

using namespace std;

int main()
{
short s = 1;
int i = 2;
float f = 4.4;
double d = 6.6;

cout << i/ static_cast<float>(s) + int (f/i + (long))d/s;


return 0;
}
ANSWER: C

Q20
What is the output of the following snipet?
#include <iostream>
#include <string>

using namespace std;

int main()

{
string s1 = "aleph";
string s2 = "alpha";
string s;

s1.swap(s2);
s2.swap(s);
s.swap (s2);
cout << s2;
}

ANSWER: D

You might also like