Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

EE502

Instruction: Answer all questions Time: 20 minutes

1. Write the output of the following program:


a. An illustrative memory block is given below, memory addresses are by the left while content
of the locations are by the right. Make use of the locations, mentally compile and display the
output. (2.5marks)

Address Content
789652 200
789653 734
789654 92
789655 3
789656 2
789657 17

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
//code
char a = 200;
char b =734;
char c =92;
char d = 3;
char e =2;
char f =17;

printf("%d \n",&a); 789652


printf("%d \n",&b+1); 789654
printf("%d \n",&c+2); 789656
printf("%d \n",&d+&e); Error
printf("%d \n",e+f); 19

return 0;
}

b. What is the scope of the variables used in the program above? (0.5 Marks)
The scope of the variable used is a local variable

c. Differentiate between char, integer. (0.5Marks)


Int = integers and can store a 16 - 32 bits number while char = character can only store 8
bits number. Also an int holds numerical values while char holds alphabetic and foreign
keys
2.
a. Differentiate between a microcontroller and a microprocessor (1 Mark)
Microprocessor consists of only a Central Processing Unit, all other memory, I/O are
connected individually, whereas the Microcontroller is smaller computer that contains a
CPU, Memory, I/O all integrated into one chip.
b. Complete the following program to check the fourth LSB of a signed number entered by the
user. The output should be “HIGH” if the bit is 1 and “LOW” if the bit is 0.

#include <stdio.h>
#include <stdlib.h>

Int main()
{
signed char a;
printf("Please enter a number:");
scanf("%d", &a);
if(a& 0b00001000 ==0) //hint: use bit masking
{
printf(“LOW”);
}
else
{
printf(“HIGH”);
}

return 0;
}

(2.5 Marks)

while(EE502_Test_1==True)

printf(“cheating is punishable, Good Luck”);

You might also like