1. Which of the following correctly declares an array?
A. int anarray[10];
B. int anarray;
C. anarray{10};
D. array anarray[10];
2. What is the index number of the last element of an array with 29
elements?
A. 29
B. 28
C. 0
D. Programmer-defined
3. Which of the following is a two-dimensional array in standard
C++ (not Visual)?
A. array anarray[20][20];
B. int anarray[20][20];
C. int array[20, 20];
D. char array[20];
4. Which of the following correctly accesses the seventh element
stored in foo, an array
with 100 elements?
A. foo[6];
B. foo[7];
C. foo(7);
D. foo;
5. What character terminates all strings composed of character
arrays?
a) \0
b) \b
c) \END
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
1
6. Evaluate the following as true or false: !(1 &&0 || !1)
a) True
b) False
c) Invalid statement
7. Which of the following is evaluated first:
a) &&
b) ||
c) !
8. What does 7/9*9 equal (in C and C++)?
a) 1
b) 0.08642
c) 0
9. The expression ! (a || b) is equivalent to which of the following
expressions?
A. (!a)&&(!b)
B. (!a)||(!b)
C. !(a && b)
D. (a || b) && (a && b)
E. (a && b)
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
2
10.
11.
Consider the function
void just(int &x, int y)
{
x+=5;
y++;
y = y-x;
}
Assuming
int g = 6, h = 10 ;
what are the values of g and h after yoyo(g, h) is called?
A. 6 10
B. 11 10
C. 6 0
D. 6 6
E. 11 0
Convert :
f = e A+B
C-D
into a valid C++ assignment.
a. f = a+b / c-d * e;
b. f = (a+b) / (c-d) * e;
c. f = (a+b)/c-d * e;
d. f = a+b / (c-d) * e;
12.
What is the output of the following?
int x = 1, y = 2, z = 3;
cout << 3 / x / (y – x);
a. 1
b. 2
c. 3
d. 4
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
3
13.
What is the output of the following statement?
cout << ((3*4*(5/2-(21%4-1)*2)+1)-1);
a. 12
b. -25
c. 47
d. 24
14.
Given int a = 7 and int b = 3 then the value of Y
will be:
Y = ( a * b % ( a + b +2) – ( a / b) )
a. 3
b. 7
c. 5
d. Non of the answers
15.
Choose the right statement.
a. A C++ program that prints 3 lines must contain 3
statements.
b. A C++ program that prints 3 lines must contain 2
statements.
c. A C++ program that prints 3 lines must contain 1
statement.
d. A C++ program that prints 3 lines may contain
more cout statements.
cout
cout
cout
1 or
16.
What are the values of x, y, z, r, s, and t after the code is
executed
int x,y,z; float r,s,t;
z=2; y=z-1; x=z+4;
r=x/y; s=r/z; t=z%y;
a. x=4, y=1, z=2, r=2, s=3, t=2.
b. x=6, y=4, z=2, r=6, s=3, t=1.
c. x=6, y=1, z=2, r=6, s=3, t=0.
d. x=4, y=4, z=4, r=2, s=2, t=1.
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
4
17.
In C++, the condition x > y > z
a. evaluates correctly and could be replaced by (x> y &&
y > z)
b. generates syntax error and should be replaced by (x > y ||
y > z)
c. evaluates correctly and could be replaced by (x > y || y >
z)
d. generates syntax error and should be replaced by (x > y
&& y > z)
18.
The expression if (num != 65) can be replaced by:
a. if (num > 65 && num < 65)
b. if ((num == 65))
c. if (num – 65)
d. if ( !(num – 65))
19.
What is the output of the following code, assuming that
x = 12;
if(x = 6)
x = x + 1;
cout << x;
a. 12
b. 6
c. 7
d. x
20.
If f is equal 1 and c is not equal an 'X', then assign the value
0 to f, else set f to 1.
a. if ((f == 1) && (c != 'X')) f = 0;
else f = 1;
b. if ((f == 1) && (c != 'X')) f = 0;
else f = 1;
c. if ((f = 1) && (c != 'X')) f = 0;
else f = 1;
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
5
21.
What is the output of the following code?
int x = 0, y = 1, z;
if(x) z = 1;
else z = 2;
if(y) z = 3;
else z = 4;
cout << z;
a. 4
b. 3
c. 2
d. 1
22.
What is the output of the following code?
int a = 7;
if(a=1)
{if(a==22) cout<<a;}
else
cout<<a;
cout<<88
a. 88
b. 788
c. 880
d. 088
23.
What is the output of the following code?
int j = 1;
while (j < 10)
{ cout << j << " ";
j = j + j%3;}
a.
b.
c.
d.
147
1 4 7 10
1258
124578
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
6
24. What is the output of the following code
int i=4;
int arr[i]={3,6,8,9};
cout<<arr[3];
a. Error (the size of the array must be constant).
b. 8
c. 9
d. 3
25. What is the output of the following code
int arr[3]={5,7,8,9};
cout<<arr[3];
a. Error (the array accept only three values with the unitization
statement)
b. 8
c. 9
d. No errors but nothing will be printed
26. What is the output of the following code
int arr[4][5]={{4,7},{6,2,1},{3},{0,5,8,9}};
cout<<arr[3][3]<<" "<<arr[2][3]<<endl;
a. 0 0
b. 0 1
c. 9 0
d.9 0
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
7
27. What is the output of the following
int arr[4]={3,6,9};
for (int i=1; i<=5;i++)
{
arr[i]=arr[0]+10;
cout<<arr[i]<<" ";
} cout<<endl;
a. Error
b. 13 16 19 20 30
c. 13 16 19
d. 13 13 13 13 13
28. What is Wrong in the following code
int arr[4]={3,6,8}; //line1
int arr2[4]; //line2
for(int i=0; i<=10; i++) //line 3
arr=arr2; //line 4
a. line 1; it needs 4 values not 3
b. line2; it must be initialized
c. line3; There is no 10 cells or arr and arr2 , it is out of range
d. line4; the equal assignment must be between cells of the array.
29. What is the output of the following code
int arr[4]={1,2,3,4};
cout<<arr<<endl;
a. 1 2 3 4
b. the address of arr[0]
c. 1
d. Error
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
8
30. The array will be filled
int arr[3][3];
for(int i=0; i<=2; i++)
for (int j=0; j<=2; j++)
arr[j][i]=10;
a. row by row
b. column by column
c. diagonal
d. there is error
31. What is the output of the following code
int x=5;
void fun(int x)
{
x=::x+3;
{
int x=1;
x=::x+10;
cout<<x<<" ";
} cout<<x<<" ";
}
void main()
{ fun(::x);
cout<<endl;
}
a. 18 3
b. 11 3
c. 11 8
d. 15 8
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
9
32. What is the output of the following code
int x=2;
void fun1(int& a)
{
a=x+10;
x=x+2;
cout<<a<<" "<<x<<endl;
}
void main()
{
int x=5;
fun1(x);
}
a. 12 4
b. 14 16
c. 14 6
d.12 14
33. What is the output of the following code
void main()
{
int x=1;
x++;
{
x=x+2;
{
int x=10;
x=x+2;
cout<<x<<" ";
}
x++;
cout<<x<<" ";
}
x=x+5;
cout<<x<<endl;}
a. 12 13 18
b. 12 5 10
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
10
c. 6 7 12
d. 12 13 9
34. What is the output of the following code
void fun()
{
static int x=4;
int y=20;
x=x+2;
y=x+y;
cout<<x<<" "<<y<<endl;
}
void main()
{
fun();
fun();
}
a. 6 26
8 28
b. 6 26
6 26
c. 6 26
8 26
d. Error
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
11
35. consider the following code
int x=4;
void fun()
{
static int a=3;
int b=10;
a=a+2;
b=a+b;
x=x+3;
}
void main()
{
fun();
fun();
}
Which one of the following is/are static variable/s
a. a
b. a b
c. a x
d. a x b
36. What is the output of the following
void fun(int a, int b=3, int& c=3, int d=5)
{ cout<<a<<b<<c<<d;
}
void main()
{i
nt x=1;
fun(5,6);
}
a. Error (c) reference parameter cannot have default value
b. 5 3 6 5
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
12
37. What is the output of the following code
int fun(int a, int b)
{
if (a> b)
return 10;
else
return 20;
cout<<"hello\n";
}
void main()
{
int x=1, y=5;
cout<<fun(y,x)<<endl;
}
a.10
b. hello
10
c. 20
d. hello
20
38. What is the output of the following
int i;
for( i=1,cout<<"A"; i<=5; cout<<"B",i+=2);
a. ABBBB
b. Error
c. ABABABAB
d. AB
39. What is the output of the following code
x=3; int r=(++x)+(++x);
a. 10
b .9
c. 6
d. 8
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
13
40. What is the output of the followng code(assume x=3, y=7)
if(x==3)
cout<<"X ";
else;
cout<<"Y”;
cout<<"X”;
a. X
b. XX
c. Y
d. XYX
41. What is the output of the following code (x=10)
switch (x+1)
{ case 1:
cout<<"A ";
case 10:
cout<<"B ";
cout<<"C ";
case 11:
cout<<"D ";
default:
cout<<"E ";
cout<<"F ";
}
a. D
b. B C
c. D E F
d. E F
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
14
42. What is the output of the following
#include<iostream>
using namespace std;
void main()
{int i=1;
for(i=3; i<=5; i++)
{if (i==4)
continue;
cout<<"A";
}}
a. AA
b. AAAA
c. A
d. AAA
For Questions from 5 to 7, find the outputs of the following C++ codes
int array[6 ]={9,8,7,6,5,4};
Ans. 5
for (int x=0;x<6;x++)
{ cout<<array[5-x]<<" ";
if (x%3= =1) cout<<"\n";
}
int f(int );
Ans. 6
void main( )
{for(int a=1;a<=5;a++)
cout<<a<<"\t"<<f(a)<<"\n";
}
int f(int x)
{ int y=x*x - 2*x +1;
return y;}
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
15
Q1) Write a function that adds the elements of two different arrays and
stores the results in a third array (all arrays are the same size).
// c = a + b
void add_arrays(int a[],int b[],int c[],int len);
Q2) Write a function that returns true or false:
– true only if a value x is found in an array a
int search_array(int a[], int len, int x);
Prepared by : Mustafa radaideh
http://www.just.edu.jo/~myradaideh
16
© Copyright 2026 Paperzz