FE Fall2023-24 Key
FE Fall2023-24 Key
Felix Babalola
Booklet A____________________________________________________January 29th, 2024
Part A: Trace the following snipets of code and give the correct OUTPUT
1)
int x= 5, y = 6, z = 7;
int funX(int x, int y){
return x > y ? x : y;
}
void funY(){
int x;
x = y - 2;
z = funX(x, y);
printf("x = %d, y = %d, z = %d \n", x, y, z);
}
int main(){
int y = 4;
funY();
printf("x = %d, y = %d, z = %d \n", x, y, z);
return 0;
}
x = 4, y = 6, z = 6
x = 5, y = 4, z = 6
2) #include <stdio.h>
int main(){
char *p = “FINAL EXAM”;
printf("%c\n", *(p + *p – 'E' + 2));
return 0;
}
A
-1-
Assist. Prof. Dr. Felix Babalola
Booklet A____________________________________________________January 29th, 2024
3)
int i = 1, x= 5, y = 10;
void funY(int A[], int x){
for(int i = 0; i< x; i++)
A[i] += y;
y += i;
}
int main(){
int arr[] = {1, 2, 3, 4, 5, 6};
funY(arr, 4);
for( ; i< x; i++)
printf("%d ", arr[i]);
4)
int x= 5, y = 10;
int fun(int y){
--y;
return y * y;
}
int main(){
94101
-2-
Assist. Prof. Dr. Felix Babalola
Booklet A____________________________________________________January 29th, 2024
5) int main(){
int D[3] = { 400, 401, 402 };
int C[3] = { 600, 601, 602 };
int i, *p1, *p2;
p1 = &D[0];
p2 = &C[0];
++p1;
++p2;
Part B
1) Given the following initializations:
i) *p ………………12………………………
v) printf(“%s”,strcpy(s1,s4)); …… Intelligence…
2 4 0
2 4 0
1 0 0
-4-
Assist. Prof. Dr. Felix Babalola
Booklet A____________________________________________________January 29th, 2024
2) What values should be assigned to int variables x, y, and z below if the following C code
prints the output as 0 5 ?
a) x = 1, y = 1, z = 4
b) x = 1, y = 1, z = 5
c) x = 1, y = 0, z = 4
d) x = 1, y = 0, z = 5
a) #define G 9.8
b) int G = 9.8;
c) float G = 9.8;
4) Which statement should be inserted in the blank line below so that the C code displays the
output as 0 2 ?
int i = 0;
-5-
Assist. Prof. Dr. Felix Babalola
Booklet A____________________________________________________January 29th, 2024
5) What is the type of the following assignment expression if i is of type float and j is of type
int?
j=i+j
int x = 3, y, i, r = 0;
scanf("%d", &y);
r += x;
a) It divides x by y
b) It multiples x by y
c) It adds x to y
d) It subtracts x from y
7) The output of the following partial C code is 30. Which statements can be inserted for line1
and line2 below?
__________________ //Line 1
printf("1");
__________________ //Line 2
printf("2");
else
printf("3");
printf ("0");
-6-
Assist. Prof. Dr. Felix Babalola
Booklet A____________________________________________________January 29th, 2024
8) The output of the following C code is 4. Which of the following may be a possible input
series entered by the user?
int i, cnt=0;
for ( ; ; ) {
scanf("%d", &i);
if (i==0) break;
cnt++;
printf("%d", cnt);
a) 0, 4, 3, 2 b) 1, 5, 6, 4, 0 c) 2, 6, 3, 0 d) 3, 2, 1, 0, 0
..............................................................................................................................
................int i = 3; ...............................
...................} ....................................................
..............................................................................................................................
-7-
Assist. Prof. Dr. Felix Babalola
Booklet A____________________________________________________January 29th, 2024
OPERATORS ASSOCIATIVITY
* / % Left to right
+ - Left to right
== != Left to right
|| Left to right
?: Right to left
= += -= *= /= %= Right to left
, Left to right
-8-