Beruflich Dokumente
Kultur Dokumente
Does the following code run without error? What is the Error?
#include <iostream>
void F1();
void F2();
void main(){
F1()
}
void F1(){
F2();
}
void F2(){
cout << “WELCOME”;
}
Question 2
What is the output of the following c++ programs?
Page 1 of 4
Question 3
What is the output of the following code, given the function definition below?
void main()
{
int a=7, b=12;
tester(a,b);
cout << a << “ “ << b;
}
Question 4
What is the output of the following programs?
#include <iostream.h>
void doSomething(int&);
void main()
{
int x=2;
cout << x << endl;
doSomething(x);
cout << x << endl;
}
Page 2 of 4
numbers(a,c);
cout << a << “ “ << b << “ “ << c << endl;
}
Page 3 of 4
int compute (int, int, const int[], const int[]);
void main()
{
int c[6] = {2,3,5,7,93,4};
int d[7] = {23,4,9,3,40,33,1};
cout << compute(2,4,d,c) << endl;
}
int compute(int start, int end, int const a[], int const
b[])
{
int sum=0;
for (int i=start, i<=end, i++)
sum += b[i] – a[i];
return sum;
}
int i=0;
const int j=5;
void first()
{
i = i+j;
int j=++i;
int i=j;
}
void main()
{
first();
cout << i << “ “ << j << endl;
}
Question 5
What is wrong with the following recursion program?
int f(int n)
{
int result = 3+2*f(n-1);
return (result);
}
void main()
{
int r,n;
cout << “Enter the value for n: “ << endl;
cin >> n;
r = f(n);
cout << “Result is: “ << r << endl;
}
Page 4 of 4