mid - ans
mid - ans
mid - ans
…………………………
……….
Duration: 1 Hour
August 2015
Instructions to Candidates:
Answer ALL questions.
There are 20 MCQ questions.
This paper contains 8 pages with Cover Page. No additional data is attached.
Write your answers in this paper itself.
Page 2 3 4 5 6 7 8 9 10 Total
Sub
total
1
Each Question is worth 1 mark. Underline the most suitable answer.
a) (I) is correct.
b) (I) and (II) are correct
c) (I) and (III) are correct
d) (I), (II), (III) are all correct.
a) Check_This
b) 007Bond
c) Upper%half
d) if
value = 5
postfix - a++ print unata passe wadi wenne
a) printf(“value=%d\n”, a); prefix- ++a print wenna kalin wadi
b) printf(“value=%d\n”, a++); wenawa.
c) printf(“value=%d\n”, ++a);
d) printf(“value=%d\n”, a--);
a) if (x==1) then
b) if (x==1){ ; }
c) if (x>=1) ; else ;
d) if (x>=1) { ; }else { ; }
1 line ekak nm wahanna ona na.
6. Assuming 'int x=10;' which of the following is a NOT valid 'C' loop.
2
7. Inspect the following code:
#include <stdio.h>
void main(void){
int i;
4 wenakn witarai.
i=0;
while( i < 10 ){
printf(" i=%d,", i);
i=i+1; 4+1=5, hinda 4n nawatinawa.
if (i = = 5){
break; continue tibbot etanin pahalata yanne na.ayet
} udata yanawa.loop eke
}
}
a) i=0, i=1, i=2, i=3, i=4, i=5, i=6, i=7, i=8, i=9,
b) i=0, i=1, i=2, i=3, i=4, i=5,
c) i=0, i=1, i=2, i=3, i=4,
d) i=6, i=7, i=8, i=9,
#include <stdio.h>
void main(void){
int i;
i=0;
while(i<10){
i=i+1;
if((i%2) = = 1){
continue; ghanna ona eka wadinne na. (anit ekata continue
}
printf(" i=%d,", i); wenawa.)
}
}
3
9. Inspect the following code:
void main(void){
int i=3;
switch(i%2){
case 0:
printf("%d is an even number\n",i);
break;
case 1:
printf("%d is an odd number\n",i);
}
}
#include <stdio.h>
void f1(int);
void main(void){
int i=5; function eka call karanawa
f1(i);
printf("value = %d\n", i);
}
4
11. Inspect the following code:
#include <stdio.h>
void main(void){
printf("%d\n", i/j);
printf("%d\n", i%j);
a) 5 b) 1 c) 1 d) 5
3 2 3 1
#include <stdio.h>
int i=2;
void main(void){
printf("i=%d\n", i);
int i=3;
{
int i=4;
printf("i=%d\n", i);
}
printf("i=%d\n", i);
5
13. Inspect the following code:
#include <stdio.h>
void f1(void);
void main(void){
int i=5;
f1();
f1();
f1();
} static - eka parak change karot eka save wenawa.
void f1(void){
static int i=4;
printf("i=%d\n", i);
i=i-1;
}
This code prints:
#include <stdio.h>
void f1(void);
void main(void){
int i=5;
f1();
f1();
f1();
}
void f1(void){
int i=4;
printf("i=%d\n", i);
i=i-1;
}
This code prints:
6
15.
“SCOPE and LIFETIME of variables refer to.”
a) Where a variable can be seen in your code, and how long the variable remains in use.
b) How useful a variable is, and the story of it's life.
c) The difficulty experienced in using a variable, and how your life expectancy was reduced
by it.
d) Who is allowed to use a variable, and what the computer feels about it.
#include <stdio.h>
function ekata eliyen tiyanawa nm global.function eka asse tinawa nm
int i=5; local.
void main (void){
int i=6; wena function ekak gattama i print karot print
printf("i=%d\n", i); wenne 5(global variable hinda)
}
17. Choose the answer which is CORRECT. global variable eka delete wenne na
a) because int i=6 is defined in main, the global variable int i=5 is deleted by the
compiler.
b) because int i=6 is defined in main, the global variable int i=5 is not accessible in
main(), but remains in memory.
c) The local variable's (i=6) is by default accessible outside the main function, by other
functions, as main is special. eliye nemei,atule tiyenne.
d) global variables and local variable declared in main() have the same scope within a
'C' program.
7
Use the following code to answer the questions 18 and 19.
#include <stdio.h>
void f1();
int i=5;
void main(void){
f1();
printf("i=%d\n",i);
}
void f1(){
i=7;
printf("i=%d\n",i);
}