You are on page 1of 2

CS 200- Introduction to Programming

Quiz: 1 Time: 15 minutes


Name: ____________________________
Roll number: ___________________________

Q: In each of the following cases state the output. In case of a syntax, run-
time or logical error write ERROR and explain where it occurs.
(10 marks)

1) #include <iostream>
using namespace std;

void Concatenate(string s1, string s2) Error: Function is of void type


{
s1 + s2; OR: Missing #include<string>
}
int main()
{ string s1 = "I am studying "; S1+s2 not saved in a different variable is not an error
string s2= “CS 200”;

cout<<Concatenate(s1,s2)<<endl;
return 0;
}

2) #include <iostream>
using namespace std; Error: The array size is 2 whereas 5 integers are being
int main() added
{
int a[2]= {1, 2, 3, 4 , 5}; OR 1
for(int i=0; i<5; i++)
2
{
cout<<a[i]<<endl;
}
return 0;
}

3) #include <iostream>
using namespace std; True
int main() True
{ int x= 2;
for(int i=1; i<4; i++) True
{
if(x=i) OR:
cout<<"true"<<endl; (there is = in whereas there should be ==)
else
cout<<"false"<<endl; Missing braces before if is not an error
}
return 0;
}

4) #include <iostream>
using namespace std;
5
int main()
{ 6
const int x= 5;
for(int i=0; i<5; i++) 7
{ 8
int j= i+x;
cout<<j<<endl; 9
j++;
x++; OR:
} Constant variable can not be changed
return 0;
}

5) #include <iostream>
using namespace std;
int main()
{
int x=5; ERROR: semi colon after while
int y=0;
while(y<=x);
{
The condition y<=x is correct and therefore is not an
cout<<”Number:”<<y<<endl;
y++; errror
}
return 0;
}

You might also like