Bristol Institute of Technology

Similar documents
Faculty of Environment and Technology

Topic 6: A Quick Intro To C. Reading. "goto Considered Harmful" History

Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009

COSC 2P91. Introduction Part Deux. Week 1b. Brock University. Brock University (Week 1b) Introduction Part Deux 1 / 14

ECE264 Fall 2013 Exam 3, November 20, 2013

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Midterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.

Dynamic Memory Allocation and Command-line Arguments

Topic 6: A Quick Intro To C

Exam 1 Practice CSE 232 Summer 2018 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga

Lexical Considerations

Lecture 07 Debugging Programs with GDB

Why C++ is much more fun than C (C++ FAQ)?

COMP 2001/2401 Test #1 [out of 80 marks]

BEng (Hons) Electronic Engineering. Resit Examinations for / Semester 1

C Language Summary (Continued)

PRINCIPLES OF OPERATING SYSTEMS

cast.c /* Program illustrates the use of a cast to coerce a function argument to be of the correct form. */

Variables and literals

27-Sep CSCI 2132 Software Development Lecture 10: Formatted Input and Output. Faculty of Computer Science, Dalhousie University. Lecture 10 p.

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Computer Programming: Skills & Concepts (CP) arithmetic, if and booleans (cont)

MIDTERM TEST EESC 2031 Software Tools June 13, Last Name: First Name: Student ID: EECS user name: TIME LIMIT: 110 minutes

Module Contact: Dr Anthony J. Bagnall, CMP Copyright of the University of East Anglia Version 2

CSE 333 Lecture 2 Memory

1 Lexical Considerations

Pointers cause EVERYBODY problems at some time or another. char x[10] or char y[8][10] or char z[9][9][9] etc.

Exercise Session 2 Systems Programming and Computer Architecture

Tokens, Expressions and Control Structures

SU 2017 May 11/16 LAB 2: Character and integer literals, number systems, character arrays manipulation, relational operator

York University Faculty Science and Engineering Fall 2008

Chapter 11 Introduction to Programming in C

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

EXAMINATION FOR THE BSC (HONS) INFORMATION SYSTEMS; BSC (HONS) INFORMATION TECHNOLOGY & BSC (HONS) COMPUTER SCIENCE; YEAR 1

Chapter 11 Introduction to Programming in C

Room 3P16 Telephone: extension ~irjohnson/uqc146s1.html

C0MP1911 Final Exam 1337 Computing 1

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

Problem Set 1: Unix Commands 1

Tutorial 1 C Tutorial: Pointers, Strings, Exec

Physics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu

CYSE 411/AIT681 Secure Software Engineering Topic #12. Secure Coding: Formatted Output

2/9/18. CYSE 411/AIT681 Secure Software Engineering. Readings. Secure Coding. This lecture: String management Pointer Subterfuge

15213 Recitation Section C

Each line will contain a string ("even" or "odd"), followed by one or more spaces, followed by a nonnegative integer.

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

Programming refresher and intro to C programming

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

CS3157: Advanced Programming. Outline

Chapter 11 Introduction to Programming in C

Introduction to Computer Systems. Exam 2. April 11, Notes and calculators are permitted, but not computers.

Review of the C Programming Language for Principles of Operating Systems

#include <stdio.h> int main() { char s[] = Hsjodi, *p; for (p = s + 5; p >= s; p--) --*p; puts(s); return 0;

Review of the C Programming Language

CSE 351. GDB Introduction

2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C

Computer Programming. The greatest gift you can give another is the purity of your attention. Richard Moss

PROGRAMMAZIONE I A.A. 2017/2018

Introduction to Computing Systems Fall Lab # 3

Multiple Choice Questions ( 1 mark)

Chapter 11 Introduction to Programming in C

Outline. Computer programming. Debugging. What is it. Debugging. Hints. Debugging

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

Chapter 11 Introduction to Programming in C

CSE 565 Computer Security Fall 2018

C Language Summary. Chris J Michael 28 August CSC 4103 Operating Systems Fall 2008 Lecture 2 C Summary

Review of Scientific Programming in C and Fortran. Michael McLennan Software Architect HUBzero Platform for Scientific Collaboration

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Chapter 11 Introduction to Programming in C

Contents. A Review of C language. Visual C Visual C++ 6.0

Functions. Using Bloodshed Dev-C++ Heejin Park. Hanyang University

IBM Rational Rhapsody TestConductor Add On. Code Coverage Limitations

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Lexical Considerations

CS 2505 Computer Organization I Test 1. Do not start the test until instructed to do so!

The University of Nottingham

ANSI C Programming Simple Programs

2 Compiling a C program

CS 0449 Sample Midterm

Modifiers. int foo(int x) { static int y=0; /* value of y is saved */ y = x + y + 7; /* across invocations of foo */ return y; }

Unit 1: Introduction to C Language. Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune

ch = argv[i][++j]; /* why does ++j but j++ does not? */

15-213/18-243, Spring 2011 Exam 2

Array Initialization

Work relative to other classes

Basic Types and Formatted I/O

Programming in C week 1 meeting Tiina Niklander

Lecture 2: C Programming Basic

Introduction to C Language

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 14

Reserved Words and Identifiers

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

How Compiling and Compilers Work

5.Coding for 64-Bit Programs

Transcription:

Bristol Institute of Technology Academic Year: 09/10 Module Leader: Module Code: Title of Module: Ian Johnson UFCETS-20-1 Programming in C Examination Date: Monday 12 th January 2009 Examination Start time: 09:00 or 13:30 Duration of Examination:3Hours Instructions to Candidates: Candidates must answer ALL questions. Materials supplied to the candidate will be: Number of Examination Booklets per Examination 1 Number of sheets of Graph Paper size G3 (Normal) 0 Number of Pre-printed OMR (Multiple Choice Answer Sheet) 0 Additional Instructions to Invigilators: University approved calculators may be used Candidates permitted to keep Examination Question Paper Material supplied by student allowed (must be collected with answer booklet) please specify: Yes Yes No Additional Specialised Material : NONE Treasury tags & adhesive triangles will be supplied as standard

Question 1. Question 2. Question 3. Pick the odd one out and explain why: double bool int What value wouldisxdigit('f') return and why? Pick the odd one out and explain why? long short double Question 4. Explain the difference between the following literals in C. How much memory would each require? 'A' "A" (4 marks) Question 5. On a Pentium architecture computer running linux, how large in bits are the following variable types: a) unsigned char b) char * c) int d) int * e) long (5 marks) Question 6. In the laboratory you have used GVD the Gnu Visual Debugger. Why is such a tool required? (4 marks) Page 1 of 7

Question 7. Consider the following poorly written C program: 1. #include <stdio.h> 2. 3. main(int argc, char **argv) 4. { 5. int y; 6. 7. y = 4; 8. printf("%4.2f\n", root2(y)); 9. 10. } 11. 12. double root2(int *x) 13. { 14. double z; 15. 16. z = sqrt((double) *x); 17. return z; 18. } When compiled with gcc Wall exam06.c the following output is produced: exam06.c:5: warning: return type defaults to `int' exam06.c: In function `main': exam06.c:9: warning: implicit declaration of function `root2' exam06.c:9: warning: double format, different type arg (arg 2) exam06.c:11: warning: control reaches end of non-void function exam06.c: At top level: exam06.c:14: warning: type mismatch with previous implicit declaration exam06.c:9: warning: previous implicit declaration of `root2' exam06.c:14: warning: `root2' was previously implicitly declared to return `int' exam06.c: In function `root2': exam06.c:17: warning: implicit declaration of function `sqrt' /tmp/ccjtkwnt.o(.text+0x4e): In function `root2': : undefined reference to `sqrt' collect2: ld returned 1 exit status a) If the compilation was successful, what would the name of the generated executable be? (1 mark) b) Explain the errors and warning in the above gcc output, suggesting improvements to the program to fix them. (12 marks) c) Having fixed the program as discussed in (b), recompilation generates the following error: exam06.c: In function `main': exam06.c:8: warning: passing arg 1 of `root2' makes from integer without a cast Explain what has caused this error and how you would fix it. Page 2 of 7

d) If the program was fixed, what would be output on line 8? (1 mark) Question 8. Explain the meaning of the following operators in C and give an example of where each could be used. a)! b) ~ c) d) (8 marks) Question 9. What is the most common cause of a segmentation fault? Question 10. Consider the following C program: 1. 2. 3. #include <stdlib.h> 4. 5. void main() 6. { 7. char x; 8. 9. x = calloc(6,sizeof(char)); 10. 11. x[0] = 'H'; //fill buffer with string 12. x[1] = 'E'; 13. x[2] = 'L'; 14. x[3] = 'L'; 15. x[4] = 'O'; 16. x[5] = '\0'; 17. 18. printf("%s\n",x); 19. 20. return 1; 21. } Page 3 of 7

When compiled withgcc Wall ansi pedantic the following output is generated: foo.c:5: warning: return type of `main' is not `int' foo.c: In function `main': foo.c:8: warning: assignment makes integer from without a cast foo.c:10: subscripted value is neither array nor foo.c:10: parse error before '/' token foo.c:12: subscripted value is neither array nor foo.c:13: subscripted value is neither array nor foo.c:14: subscripted value is neither array nor foo.c:15: subscripted value is neither array nor foo.c:17: warning: implicit declaration of function `printf' foo.c:17: warning: format argument is not a (arg 2) foo.c:19: warning: `return' with a value, in function returning void Explain what the above warnings & errors mean, and how you would modify this program to prevent them. (12 marks) Page 4 of 7

Question 11. Consider the following C program: 01: 02: main() 03: { 04: int x = 3; // my variable 05: 06: if (x=1) 07: printf("hello\n"); 08: else 09: printf("world\n"); 10: } 11: When compiled with gcc Wall the following output is generated: foo.c:3: warning: return type defaults to `int' foo.c: In function `main': foo.c:6: warning: suggest parentheses around assignment used as truth value foo.c:7: warning: implicit declaration of function `printf' foo.c:10: warning: control reaches end of non-void function Explain what each of the four warnings mean, and how you would modify this program to prevent these warnings. (10 marks) Question 12. You wish to compute the cosine of 90 degrees a) Which header file would you need to include? b) Write a C statement to assign the result to a variable X. Question 13. What would you expect to find in a C header file (*.h)? (3 marks) Question 14. The C operator -> is a shorthand for a more complex notation. a) Explain the circumstances in which it would be used b) Write an example of the more complex notation Page 5 of 7

Question 15. Consider the following C program: #include <stdio.h> main() { int x; x = 0xffffffff; printf("%d\n",x); } What value will be printed? (1 mark) Question 16. Consider the following C fragment unsigned char x; x = 0xaa; What is the value of x in binary? (1 mark) Question 17. Consider the following declaration: int MY_VAR, i, total%, UFS001, long, &, total-val, z.height, *q, 1st, count; Which of the above variables would not be legally named in C? Explain why. (12 marks) Question 18. Consider the following C fragment: double x; int y=9; int z=4; x = y/z; /* statement (1) */ a) What value does x contain and why? b) Rewrite statement (1) to ensure the answer is 2.25 Page 6 of 7

Question 19. An unsigned char variable A has the value 187 decimal. a) What is the value in binary? b) What is the value in hexadecimal? c) Write C statements using only bitwise operators to: i. Divide the value by 16 ii. Set the most significant bit without altering any other bits iii. Clear the least significant bit without altering any other bits (5 marks) Question 20. In C, the function main traditionally has a standard declaration. a) Write a standard declaration for main. b) Explain what the arguments to main are, and how you would access its return value (5 marks) END OF QUESTION PAPER Page 7 of 7