You are on page 1of 5


2015 / 2016 ACADEMIC YEAR

DAY: THURSDAY DATE: 10/12/2015

TIME: 09:00 – 11:00AM STREAM: Y1S2

1. Section A: is compulsory, and attempt any other two questions

from section B:
2. Do not write anything on this question paper.

QUESTION ONE [30 marks]
a. Identify any four keywords used in C language (4 marks)

b. i) Explain the use of the following format specifiers as used in C: (2 marks)

(1) %d (2) %f (3) %s (4) %c

c. ii) Look at the code below and show how you would display the output with only two
places of decimal? (2 marks)

int main ( )

{ float a = 10.250000;
printf(“the value of a is %f”, a);

Page 1 of 5
d . Explain each of the following data types as used in C programming language: (2 marks)

i) int (ii) char (iii) float (iv) double

e. Explain the differences between a variable and a constant as used in C language (2 marks)

f. Explain the differences between Formal parameters and Actual parameters (4 marks)

g. Identify the differences between the following two terms in relation to functions: (2 marks)

Predefined standard library functions and User Defined functions

h. Write a program that would determine if a character entered is a vowel or not by entering
any one character and showing some output (6 marks)

i) what is an array? (2 marks)

j. The following program has some errors, make the corrections and show the output. (4 marks)

int add(int d, int e);

main( )
int a, b, c;
c = add(a, b);
printf ( "value of c is %d", c ) ;
int add(int x, int y)
{ int p;
p = e*d;
return p;}

QUESTION TWO (20 marks)
a) i) Outline six benefits of pointers as used in C language (3 marks)
ii) Show how you would declare and initialize a pointer in C- language (3 marks)

b. i) Show how you would declare and initialize an integer array of four elements. (2 marks)

Page 2 of 5
ii) Write a C code to display the output of the above mentioned elements in b(ii) (4 marks)

iii) What would happen if the size of an array is omitted during declaration? (2 marks)

c. Explain the rules for writing variable names in C language (4 marks)

d. Differentiate between a keyword and an identifier as used in C language (2 marks)


a. Sketch a simple code to show how each of the following operators are used in C
language: (6 marks)

i) Arithmetic operators
ii) Assignment operators
iii) Relational operators

b. Study the following two codes written in C and answer the questions that follow:
i) int main()
int a = 0;
while(a < 3)
printf("loop iteration is %d\n", a);
if(a == 2) break;
printf(" go to the next round\n");
return 0;
ii) int main()
int a = 0;

while(a < 6)

Page 3 of 5
if(a == 4) continue;
printf("loop iteration is %d\n", a);

printf(" go to the next round\n");

return 0;

i) Show the output of each code (6 marks)

ii) Explain the differences between them (4 marks)

c. Show the output of the following C code: (4 marks)

int main()
int j=0;
printf("Value of variable j is: %d\n", j);
while (j<=8);
return 0;

QUESTION FOUR (20 marks)

a. Identify and explain three types of decision making in relation to if control statements in C

language. (6 marks)

b. Explain the nature of the following code, and state the output. (6 marks)

#include <stdio.h>
void count(int x);
int main()
int num;

Page 4 of 5
printf("Enter a positive integer:");
void count(int x)
printf("%d\n", x);
if(x < 0)
c. Write a C code to show how to find the memory size of a given integer variable (6 marks)
d. Explain the importance of using comments in C programming (2 marks)

QUESTION FIVE (20 marks)

a. Write a program in C whereby the main() function would call another function to print/display
exactly the

following output: (6 marks)

My name is Tom
How are you?

b. Construct a C code to show how to swap two integer numbers entered from the keyboard
(6 marks)
c. Using a conditional operator, write a program in C to find if a number entered from the

keyboard is odd or even. (8 marks)

Page 5 of 5