

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
A past exam paper from the c programming module of the bachelor of engineering in electronic engineering, applied electronics design, and communications systems at cork institute of technology. The exam consists of two questions, each worth 50 marks, and covers topics such as global variables, preprocessor directives, functions, bitwise operators, arrays, pointers, and switch statements. Students are required to write programs to demonstrate their understanding of these concepts.
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Answer any two questions [each 50 marks] Maximum available marks is 100.
Use appropriate comments and indentation in program code.
Examiners: Mr. P Cogan Mr. D. Denieffe Dr. R. Dubhghaill
Q1. (a) Explain why the use of global variables is normally avoided in program
development. [10 marks]
(b) Explain using appropriate examples what the ‘#define’ directive is used for in the C language. [10 marks]
(c) Demonstrate how functions are used in C by writing a program that reads in resistivity (ρ), length (l) and cross-sectional area (A) and which then passes
these values to a function. The function should calculate resistance ( A
l R
and return the result. The main program should then display this value (R). [10 marks]
(d) Explain what each line does in each of the following two programs. [20 marks] (i)#include <stdio.h> void main (void) { signed int a = 2, b = 9, c = 0x9; float d = 1e1; a==b; b-=c++; printf ("%d\t%d\t%d\n",a,b,c); a+= c = 5*(int)d; fprintf (stdout,"%d\t%4.2f\t%d\n",a,d,c); }
continued overleaf ….
(ii)#include <stdio.h> main () { float i[5]={9.0,11.0,13.0,15.0,17.0}; float p = &i[1]; int h; h=(int)i[2]; h<<=1; printf ("%d\t%4.1f\n",h,p); printf("%d\t%4.1f\t%u\t%u\n",--h,*p,p,(p++)); }
Q2. (a) Using example programs to illustrate your answer write a note discussing any TWO of the following with reference to the C programming language; (i) The usage of the ‘continue’ statement in C. (ii) The use of arrays. (iii) Storage classes. (iv) Pass by reference. [20 marks]
(b) What does the following program display on the screen? Explain your answer. [12 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) An electronic device reports an internal fault by displaying a two digit hex number on its display. Five bits in this hex number represent the type of error as indicated in the table overleaf. You are required to produce a program to assist technicians to find the type of error being reported by the device. Write a program that can be used to check the number displayed and report on the types of error. Your program should read in the hex number displayed and report on which types of error are reported. If more than one of the bits is set your program should list all of the errors. It should repeat until the user decides to quit. continued overleaf ….