0% found this document useful (0 votes)
19 views5 pages

CS101 E Quiz 2

This document is a quiz for a CS101 Introduction to Computing and Programming course, consisting of 23 questions that test knowledge of programming concepts and code outputs. Students are instructed to answer all questions by encircling the correct choice and writing outputs for code snippets. The quiz has a maximum time limit of 30 minutes.

Uploaded by

Sam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

CS101 E Quiz 2

This document is a quiz for a CS101 Introduction to Computing and Programming course, consisting of 23 questions that test knowledge of programming concepts and code outputs. Students are instructed to answer all questions by encircling the correct choice and writing outputs for code snippets. The quiz has a maximum time limit of 30 minutes.

Uploaded by

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

Quiz #2

CS101 (E) Introduction to Computing and Programming


Max. Time 30 minutes

Name: - ________________________ Reg. No. :- _______________ Sec: E

Note:
 Attempt all questions. Please encircle the correct choice.
 For all snippets of code, assume that they are written in main function with return statements.
 Overwriting OR Cutting is not allowed.

For Q1 –Q16 write the output of the program according to the code given.

1)
int x = 10, y = 20 ;
if ( x = y )
cout<<”Equal”<<endl ;
else
cout<<”Not equal”;

Output:-

2)
int x = 10;
if ( x = = 10 )
cout<<”Good\n”;
else
cout<<”Bad”<<endl ;
cout<<”Quiz 2\n”;

Output:-_________________

3)
int d=0;
switch (d)
{
case 0:
cout <<"we have a 0\n";
case 1:
cout<<"We have a 1\n";
case 4:
cout<<"We have something else";
default :
cout<<"Invalid input";
}

Output:- __________________
4)
int d=2;
switch (d)
{
case 0:
cout <<"we have a 0\n";
break;
case 1:
cout<<"We have a 1\n";
break;
case 4:
cout<<"We have a 2\n";
break;
default :
cout<<"Invalid input";
}

Output:- _________________

5)
int x=2,y=0;
if (x=y)
cout<<"True\n";
else
cout<<"False";

Output:-

6)
int a=0;
if (a=2)
cout<<a;
else
cout<<"Error"<<endl;

Output:- ____

7)
int a=0;
if (0)
cout<<a;
cout<<"Error"<<endl;

Output:-

8)
if (!(1 && !(0 || 1)))
cout<<"True\n";
else
cout<<"False";

Output:-
9)
int x=1;
int z=0;
z=(x>=1 ? 10 : 20);
cout<<z<<endl;

Output:-

10)
int x=0;
if (x)
{
cout<<"Enter a number\n";
cin>>x; }
Output:-

11)
int i = 5, j = 6, k = 7, n = 3;
cout << i + j * k - k % n;
cout << “\t” << i / n << endl;

Output:-

12)
float weight = 50.0;
switch(weight)
{
case 50.0:
cout<<"Your weight is "<<weight<<" kg";
break;
case 60.0:
cout<<"Your weight is "<<weight<<" kg";
break;
case 70.0:
cout<<"Your weight is "<<weight<<" kg";
break;
default:
cout<<"You are overweight "<<endl;
break; }
Output:___________________

13)
int a=5, b=5;
int p= ++a + b++;
int q= --a + b;
int r= --a + (++b);
int s= --a + --b;
cout<<p<<" "<<q<<" "<<r<<" "<<s;

Output:-______________________
14)
int a=5, b=8;
int x= (a=b);
int y= (a<b);
int z= (a>b);
cout<<x<<y<<z;

Output:-

15)
int a=5, b=0;
if(a=b)
cout<<"Good";
else
cout<<"Bad";

Output:-_________________

16)
int a=5, b=0;
if(a=b);
cout<<"Good";
cout<<"Bad";

Output:-

17) Which of the following are not true


a) It is mandatory to write else with if
b) Else can be written without If
c) Both a and b
d) None of the above

18) Syntax errors have their effect at execution time.


a) True
b) False

19) What is required to avoid falling through from one case to the next in a switch statement?
a. end
b. break
c. Stop
d. semicolon
20) What is the error in following code
int x=2;
if (x==2)
cout<<"True\n";
else (x==1)
cout<<"False";
21) what will be the output ?
for ( int i =1; i < 10; i++ ) {
int j = 5;
if (i % j)
continue;
cout << i << " ";
}

a) 2 3 4 5
b) 3 4 5
c) 4 5
d) 5

22)
int a = 10;
for (int i=10, j=0; i<=10 && j>=0; i++, j++)
{
cout<<a%10;
}
a) 0
b) Infinite loop
c) Nothing
d) 10

23)
int a = 10;
for (int i=0; i<5; i++)
{
if((++i)/2==0)
continue;
cout<<a<<" ";
}

a) 10 10
b) 10 10 10
c) 01234
d) 10 10 10 10 10

You might also like