

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Answer any four questions [each 25 marks] Maximum available marks is 100.
Examiners: Mr. P. Cogan Mr. J. Berry Dr. R. O Dubhghaill
Q1. (a) Explain why the use of global variables is normally avoided in program
development. [5 marks] (b) Explain using appropriate examples what the ‘#define’ directive is used for in the C language. [5 marks] (c) Give the syntax and an example of the usage of the ‘continue’ statement in C. [5 marks]
(d) What do the following two programs display on the screen? Explain your answer. [10 marks] (i)#include <stdio.h> void main (void) { signed int a = 2, b = 4, c = 0x8; float d = 1e1; a==b; b-=c++; printf ("%d\t%d\t%d\n",a,b,c); a+= c = 5d; fprintf (stdout,"%d\t%4.2f\t%d\n",a,d,c); } (ii)#include <stdio.h> void main (void) { float y[5]={10.0,11.0,12.0,13.0,14.0}; float p = &y[3]; register long h; h=(long) p; h>>=2; printf ("%lu\t%4.1f\n",h,p); printf("%d\t%4.1f\t%u\t%g\n",--h,p, p,(++p)); }
Q2. (a) Write a note discussing any TWO of the following with reference to operating systems; (i) Semaphores. (ii) Mutual exclusion. (iii) Process Switching. (iv) Deadlock. [8 marks]
(b) What does the following program display on the screen? Explain your answer. [6 marks] #include <stdio.h> void main () { unsigned long x= 0x10000001; long int y=2048; char z=3; printf ("126 | x = %lx\n",126|x); printf ("250 & y = %ld\n",250&y); printf ("0x07 ^ z = %x\n",0x07^z); printf ("3 << 2 = %d\n",3<<2); printf ("Z >>=1 = %d\n",z>>=1); printf ("~z = %d\n",~z); }
(c) Design a C program that reads in an unsigned integer from the keyboard. The program should display the number in binary and then calculate the even parity of the number. [11 marks]
Q3. (a) Discuss the possible states that a process may have using an appropriate state
transition diagram. [5 marks]
(b) With reference to the C language explain what is meant by ‘recursion’. Mention some of the advantages and disadvantages of recursion and give an example. [5 marks]
(c) With reference to the C language explain what is meant by ‘pass by reference’ using appropriate examples. [5 marks]
(d) An integer is said to be prime if it is only divisible by itself and 1. Write a program that determines whether an integer entered by the user is prime or not. The program should use a function to determine if the number is prime. [10 marks]