Sie sind auf Seite 1von 4

Question 1

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?

int my_function(int, int)


void main(){
int temp = 0;
int var1 = 3;
int var2 = 5;
temp = my_function(var1, var2);
}
int my_function(int x, int y){
return x+y;
}
#include <iostream.h>
void showDub(int);
int main(){
int x=2;
showDub(x);
cout << x << endl;
return 0;
}
void showDub(int num){
cout << (num*2) << endl;
}

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

void tester(int m, int &n)


{
n = n – 2 * m;
m = 2 * m;
}

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

void doSomething(int& num)


{
num = 0;
cout << num << endl;
}
void main (){
int a=4, b=10;
a = aFunction(a,b);
cout << a << “ “ << b;
}
int aFunction (int j, int &k)
{
while (j<k)
{
j++;
k -= 2;
}
}
void main()
{
void numbers (int x, int & y);
int a,b,c;
a=22;
b=90;
c=14;
numbers(a,a);
numbers(a,b);

Page 2 of 4
numbers(a,c);
cout << a << “ “ << b << “ “ << c << endl;
}

void numbers (int x, int &y)


{
int b;
x += 6;
y += 11;
b = 55;
cout << b << “ “ << x << “ “ << y << endl;
}
int square (int& a)
{
a=a*a;
return a;
}
void main()
{
int a=2;
cout << “Is “ << square(a=square(a)) << “ equal
to”;
cout << a << “^4?” << endl;
}
int test(int n1, int n2)
{
cout << n2 << n1 << endl;
return n2*n1;
}
void main()
{
int n1=2, n2=3, n3=4;
n2 = test(test(n1,n3),n2);
cout << n1 << n3 << n2 << 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

Das könnte Ihnen auch gefallen