1)What is the output of the following [C++ Programming]
#include<iostream>
using namsespacestd;
void
PrintSequence(int StopNum)
{
int Num;
Num=1;
while(true)
{
If(Num>=StopNum)
throw Num;
cout<<Num;
Num++;
}
}
int main(void)
{
try{
PrintSequence(20);
}
catch(int ExNum)
{
cout<<”Caught
an exception with value:”<<ExNum;
}
return 0;
}
a) Compile
error
b) Prints
first 19 number and throw exception at 20
c) Prints
first 19 numbers
d) None
of the mentioned
Ans: b
2) What
is the output of the following [C++ Programming]
#include<iostream>
using namsespace std;
#define PR(id)
cout<<”The value of “ #id” is “<<id
int main()
{
int i=10;
PR(i);
return 0;
}
a) 15
b) 10
c) 20
d) None
Ans: b
It is just printing
declared value
3) Which
of the following % operation is invalid
a) 4%8f
b) 4%8
c) 4%8l
d) b
and c
Ans: a
4) What
is the output of the following code?[Datatypes]
#include<stdio.h>
int main()
{
float
a=5.477777777777;
printf(“%f”,a);
return 0;
}
a) 5.48
b) 5.478
c) 5.477777
d) 5.477778
Ans:d
Float is 6bit
precision. While printing after decimal point 6 digits printed if the value in
the 7th value is >=5 then sixth digit is rounded to next
integer.
5) In
a 32-bit compiler, which 2 types have same size?[Data types]
a) Short
and int
b) Float
and double
c) Int
and flaot
d) Char
and int
Ans: c
In 32-bit compiler, sizeof(char) is 1, sizeof(int) is 4, sizeof(float) is 4,
sizeof(double) is 8 bytes.
6) What
is the output of the following code[Datatype]
#include<stdio.h>
int main()
{
int x=97;
char y=x;
printf(“%c”,y);
}
a) b
b) 97
c) Runtime
error
d) a
Ans:d
97 is the ascii value of a
7) What
is the output of the following code[C++ Arrays]
#include<iostream>
int main()
{
int
a[2][4]={3,6,9,12,15,18,21,24}
cout<<*(a[1]+2)<<*(*(a+1)+2)<<2[1[a]];
return 0;
}
a) Compile
error
b) 21
21 21
c) 15
18 21
d) 24
24 24
Ans: b
a[1][2]=
*(a[1]+2)=*(*(a+1)+2)=2[1[a]]=21
8)What
is the output of the following code[Constructor and Destructor]
#include<iostream>
using namespace std;
template
class Test
{
public:
Test()
{
};
~Test()
{
};
type Funct1(type
Var1)
{
return Var1;
}
type Funct2(type
Var2)
{
return Var2;
}
};
int main()
{
Test Var1;
Test Var2;
count<<Var1.Funct1(200)<<endl;
count<<Var2.Funct2(3.123)<<endl;
return 0;
}
a) 3.123
200
b) 200
c) 200
3.123
d) 3.123
Ans: c
Here we are passing
the values and getting it back from template and we are using the constructor
and destructor for the function template.
9) What
is the output of the following code[C++ strings]
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
string str(“nobody
does like this”);
string key(“nobody”);
size_t f;
f=str.rfind(key);
if(f!=string::npos)
str.replace(f,key.length(),”everybody”);
cout<<str<<endl;
return 0;
}
a)nobody does like
this
b)nobody
c)everybody does like
this
d)everybody
Ans: c
rfind is used to find
the characters in the string and replace is used to replace with certain
characters.
10) Identify
the user-defined types from the following[C++ Datatypes]
a) (B) classes
b) (D) int
c) both A and B
d) (A) enumberation
Ans:c
Coding
Question:
Q) Given
a maximum of 4 digit number integer to the base of 17
(10->A,11->B,12->C 13->D 14->E 15->F 16->G) as input and
output it's decimal value
Input1
1A
Output
2 27
Input2
23GF
Output
10980
No comments:
Post a Comment