1. What type must
a variable be if you want to store the number 9.8987 in it?
2. What is the
proper way of declaring and initializing a variable in the same line?
3. What is the
value of the variable result after the execution of the
following code segment?
int a=2, b=2, c=6, result;
result = a * b + a + c / 2; |
4. If two arithmetic
operators in an expression have the same precedence, they work according
to their:
5. Which of the
following is not a valid boolean expression.?
6. Which of the
following operators has the highest precedence?
7. What is the
value of result variable after the execution of the following
code segment:
int
a = 8;
int b = 9;
int c = 0;
int result=100;
if (a != b && c == 0 ) result++;
else --result; |
99
100
0
101
8. Which of the
loop statements is ideal for situations that require a counter
9. Convert the
following while loop to a for loop
|
a =
8; sum=0;
while ( a > 0 ) { sum = sum + a; a= a - 1; }
|
10. How many times
will the value in the variable tmp
be displayed in the following program segment? (assume output displays
the value of the variable).
|
int
x, y, z; int tmp=0;
for
(x=0; x<2; x++)
for (y=0; y<2; y++)
for (z=0; z<2; z++) output (tmp);
|
11. What is the
value of the variable result
after the execution of the following code segment?
|
a =
5; result=10;
while ( a++ < 10 ) { result ++; }
|
12. What is the
value of the variable result after the following switch
statement?
|
int
result=0;
int option=1;
switch (option) {
case 0: result=result+1;
case 1: result=result+2;
case 2: result=result+3;
}
|
13. What is the
output after the following for statement? (assume output displays the
value of the variable).
|
for
(int i=0; i<10; i++) {
if
(i>=2 && i<=6) continue;
else output ( i );
}
|
14. The _________
statement causes a loop to terminate immediately.
15. After declaring
an array of 5 integers, what is the output of the following code segment:?
(assume output displays the value of the variable)
|
for
(int i = 0; i < 5; i++) {
array[i] = i * i ;
}
output
(array[3] );
|
16.Function getValue
has ____ parameter(s) and its return type is _____
|
double
getValue (int x, float y) {
/*
body of the function*/
}
|
17. The keyword
_______ indicates that a function/method does not return a value.
18. What is the
output of the following segment code after calling the
function/method display ?
|
void
disp ( ) {
int
i=10;
duplicate ( i );
output(i);
}
static void duplicate (int i) {
i=i*2;
}
|
19. The scope
of a _______ variable starts from its declaration and continues to the
end of the block that contains the variable
20. When passing
an array as an argument to a function, the funtion __________