



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Main points of this past exam are: Enumeration, Appropriate, Cast Operator, Statement, Programs, Cpu Scheduling, Mutual Exclusion
Typology: Exams
1 / 5
This page cannot be seen from the preview
Don't miss anything!




(NFQ – Level 7)
Answer any four questions [each 25 marks] Maximum available marks is 100.
Examiners: Mr. P Cogan Mr. D McCartney Mr. P. O’Donnell
Q1. (a) Explain what is meant by ‘enumeration’ using an appropriate example of enumeration in the C language. [5 marks]
(b) Explain using appropriate examples what the ‘cast operator’ is used for in C expressions. [5 marks]
(c) Discuss, using an example, the usage of the ‘break’ 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> const unsigned int SET = 0x01; void main ( void ) { unsigned int a, b = 5, c; float d = 5.0; b = sizeof(b); c = SET; ++c; d++; printf("\t%u\t%u\t%u\t%f\n",a,b,c,d); a=b=c; b=(unsigned int)(d/2.0); d*=2.0; fprintf (stdout,"\t%u\t%4.2f\t%u\n",a,d,b); } continued overleaf ….
(ii) #include <stdio.h> void main (void) { int y[]={10,12,14,16,18}; int p = &y[1]; int h,k; h=y[2]; h<<=1; k=(p++); printf ("%d\t%d\t%d\n",h,k,p); k=k^0x0f; printf("%d\t%d\t%d\t%u\n",--h,p,k,(p++)); }
Q2. (a) Write a note discussing any TWO of the following with reference to operating systems; (i) CPU scheduling. (ii) Mutual exclusion. (iii) Starvation. (iv) Synchronisation. [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= 0x10000011; 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 characters from the keyboard. Each character’s ASCII code should be modified so that the most significant bit and least significant bit are swapped. The original character and the new one should be displayed on the screen as well as the ASCII codes of the two characters. The program should stop when an amperstand (@ symbol) is entered. [11 marks]
continued overleaf ….
(i) To read in the name of the file to display using command line arguments.
(ii) If command line arguments are not used (or if an invalid name was supplied), your program should insist on the user entering a valid filename.
(iii) The program should display the contents of the file neatly on screen in hexadecimal.
(iv) The program should offer the user the option of saving the file contents in hexadecimal format to a text file.
(v) If the source file contents were saved in a text file, the program should report on how many values were written to the text file. [15 marks]
ooooOOOOoooo