MIDTERM EXAM. CS 217 October 28, Name: Precept: Honor Code: Score: Problem Score Max

Similar documents
ECE264 Fall 2013 Exam 3, November 20, 2013

CIS 2107 Computer Systems and Low-Level Programming Fall 2011 Midterm

THE UNIVERSITY OF WESTERN ONTARIO. COMPUTER SCIENCE 211a FINAL EXAMINATION 17 DECEMBER HOURS

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

COMP1917 Computing 1 Written Exam Sample Questions

15213 Recitation Section C

Problem 2 Add the two 2 s complement signed 8-bit values given below, and express your answer in decimal.

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

ECE264 Fall 2013 Exam 2, October 24, 2013

11 'e' 'x' 'e' 'm' 'p' 'l' 'i' 'f' 'i' 'e' 'd' bool equal(const unsigned char pstr[], const char *cstr) {

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

CIS 2107 Computer Systems and Low-Level Programming Fall 2011 Midterm Solutions

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

Kurt Schmidt. October 30, 2018

PRINCIPLES OF OPERATING SYSTEMS

CSCI 2132 Final Exam Solutions

JTSK Programming in C II C-Lab II. Lecture 3 & 4

CMSC 313 Fall2009 Midterm Exam 1 Section 01 October 12, 2009

This is CS50. Harvard University Fall Quiz 0 Answer Key

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

ESC101N: Fundamentals of Computing End-sem st semester

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

CSE 303, Spring 2009 Final Exam Wednesday, June 10, 2009

Student Number: Computer Science 211b Final Examination. 28 April hours

CS 237 Meeting 19 10/24/12

Class Information ANNOUCEMENTS

Intermediate Programming, Spring 2017*

Floating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions

Principles of C and Memory Management

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

CSE 333 Midterm Exam Sample Solution 7/29/13

CSE 333 Midterm Exam 7/29/13

COMP 2355 Introduction to Systems Programming

2 Compiling a C program

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

The University of Nottingham

CSSE 332 OPERATING SYSTEMS

COS 126 MIDTERM 1, FALL

CS61, Fall 2012 Section 2 Notes

ECE264 Fall 2013 Exam 1, September 24, 2013

lectures/7/src7/bmp.h /**************************************************************************** * bmp.h * Computer Science 50 * Problem Set 5

Intermediate Programming, Spring 2017*

Overview of today s lecture. Quick recap of previous C lectures. Introduction to C programming, lecture 2. Abstract data type - Stack example

ECE264 Spring 2013 Final Exam, April 30, 2013

CSE 333 Autumn 2013 Midterm

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

Final Exam 1 /12 2 /12 3 /10 4 /7 5 /4 6 /10 7 /8 8 /9 9 /8 10 /11 11 /8 12 /10 13 /9 14 /13 15 /10 16 /10 17 /12. Faculty of Computer Science

CSE 333 Lecture 7 - final C details

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

University of Toronto

Do not start the test until instructed to do so!

CSE 303 Winter 2008 Midterm Key

CGS 3460 Summer 07 Midterm Exam

EE 312 Fall 2018 Midterm 1 Version A October 10, 2018

CS240: Programming in C. Lecture 2: Overview

SOFTWARE Ph.D. Qualifying Exam Spring Consider the following C program which consists of two function definitions including the main function.

CIS 2107 Computer Systems and Low-Level Programming Fall 2010 Midterm

Data Representation and Storage. Some definitions (in C)

Computer Programming: Skills & Concepts (CP) Strings

Homework 3 CS161 Computer Security, Fall 2008 Assigned 10/07/08 Due 10/13/08

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

SOFTWARE Ph.D. Qualifying Exam Fall 2017

CSE 333 Midterm Exam 2/14/14

ECE264 Spring 2014 Exam 2, March 11, 2014

CS61c Summer 2014 Midterm Exam

CSCI 350: Getting Started with C Written by: Stephen Tsung-Han Sher June 12, 2016

CSE 303 Midterm Exam

CS300 Final Review Questions 1

COS 126 General Computer Science Spring Midterm 1

EECE.2160: ECE Application Programming Fall 2017 Exam 3 December 16, 2017

Midterm Review. CS 211 Fall 2018

Intermediate Programming, Spring 2017*

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

ECE264 Spring 2013 Exam 1, February 14, 2013

Understanding Pointers

CS 3113 Introduction to Operating Systems Midterm October 11, 2018

CS 3113 Introduction to Operating Systems Midterm October 11, 2018

FORM 2 (Please put your name and form # on the scantron!!!!) CS 161 Exam II:

A Fast Review of C Essentials Part I

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

CS 0449 Sample Midterm

ECE 250 / CS 250 Computer Architecture. C to Binary: Memory & Data Representations. Benjamin Lee

CS 237 Meeting 18 10/22/12

CSI 402 Lecture 1 (Programs in Multiple Files and make) 1 1 / 20

Review: C Strings. A string in C is just an array of characters. Lecture #4 C Strings, Arrays, & Malloc

Functions. Chapter 5

Lecture 02 C FUNDAMENTALS

Portland State University. CS201 Section 5. Midterm Exam. Fall 2018

C Language Part 3. Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

MPATE-GE 2618: C Programming for Music Technology. Unit 5.1

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

COMP26120: Pointers in C (2018/19) Lucas Cordeiro

Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links

High Performance Computing in C and C++

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

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

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

Parameter passing. Programming in C. Important. Parameter passing... C implements call-by-value parameter passing. UVic SEng 265

CSE 333 Midterm Exam 7/27/15 Sample Solution

CSE 333 Lecture 2 Memory

Transcription:

MIDTERM EXAM CS 217 October 28, 1999 Name: Precept: Honor Code: Score: Problem Score Max 1 15 2 5 3 10 4 15 5 5 6 10 7 10 Total 70 1

1. Number Systems (a) Translate the following decimal numbers to binary, and binary numbers to decimal. Assume a sign magnitude representation for binary numbers. Assume all binary numbers are 8 bits. = = = = (b) Translate the following decimal numbers to 2 s complement form, complete the arithmetic operation, and translate the result back into decimal. Indicate if overflow occurs, assuming 8-bit words. Show your work. i. 10 + 45 ii. -40-20 iii. -40-90 2. Suppose the following three variables have been defined. Assume 32-bit integers. unsigned int a = 0x30cf0034; unsigned int b = 0x4a98ff72; unsigned int c; Write the 2-3 C instructions needed to assign the high-order 20 bits of a, followed by the high-order 12 bits of b, to variable c. That is, after the instuctions, c should contain 0x30cf04a9. (Note: you may not use the constant 0x30cf04a9 in your answer.) 2

3. Show the output for each of the following two programs. (a) counter.h int get_counter(void); counter.c static counter; int get_counter(void) int counter = 5; return ++counter; main.c #include "counter.h" static counter; int main(void) printf("%d\n", counter); counter = get_counter(); printf("%d\n", counter); counter++; printf("%d\n", counter); return 0; (b) main.c #define mymul(a, b) \ int z = (a * b); \ printf("%d\n", z); \ return z; \ int main(void) int x = 5, y = 6; mymul(x + 2, y); printf("%d %d\n", x, y); return 0; 3

4. Give the declaration/definition for each of the following structures, types, and variables. You can use types and structures defined in early sub-problems to declare variables in later sub-problems. (a) Give the definition of structure day that has two components: date (a pointer to an array of 3 integers), and events (a pointer to a pointer to characters). (b) Give the declaration of variable month, which is a pointer to structure day element. Also give the definition of structure day element, which consists of two components: today (of type structure day), and tomorrow (a pointer to structure day element). (c) Declare variable year as an array of 12 pointers to structure day element. (d) For the following definition (struct day element *(* year[12]);), describe in words what year+1 points to. Limit your answer to the space provided. (e) Define variable apply that points to such a function that takes two arguments: x (an array of 30 pointers, each pointing to any type of object), and y (a pointer to a function that has two arguments, one is a pointer to any type of object and the other is a pointer to pointer to any type of object). Both of the functions that y and apply point to return nothing. (f) Suppose that we have already defined functions f1, f2, f3 and f4 earlier in the program. Each of these four functions takes a pointer to any type of object as an argument and returns an integer. Declare a variable funcs to be an array of four pointers to these functions. (g) Show how the third function in array funcs is invoked on integer variable a. 4

5. The following program implements a simplified link list. It is syntactically correct (i.e., it successfully compiles), but it contains a serious flaw that may cause it to behave in an unpredictable way. Identify the flaw. #include <stdlib.h> #include <string.h> typedef struct node void *val; struct node *next; node; typedef node * pnode; int getfoo (int i) /* some random computation */ int x = 1; int y = 2; int z = 3; return (i + x + y + z); pnode insert1 (pnode p, int level) char one[4]; pnode pnew; strcpy(one,"one"); pnew = malloc (sizeof (node)); pnew->val = one; pnew->next = p; if (level > 1) pnew = insert1 (pnew, level-1); return pnew; void main() pnode s, q; char *zero = "zero"; int foo; s = malloc (sizeof (node)); s->val = zero; s->next = NULL; s = insert1 (s, 1); foo = getfoo(1); q = s; while (q!= NULL) printf ("%s\n", (char *)q->val); q = q->next; return; 5

6. The following program uses a binary tree to store integer values. It will compile, but core dump when executed. (a) Identify the problem and suggest a fix. (b) Show what the corrected program outputs. #include <stdlib.h> typedef struct tree int val; struct tree *left, *right; tree; typedef tree * ptree; ptree insert (ptree p, int nval) ptree pnew; if (p == NULL) pnew = malloc (sizeof (ptree)); pnew->val = nval; pnew->left = pnew->right = NULL; return pnew; else if (nval < p->val) p->left = insert (p->left, nval); else p->right = insert (p->right, nval); return p; void traverse (ptree p) if (p!= NULL) traverse (p->left); printf ("%d\n", p->val); traverse (p->right); void main() ptree p = NULL; p = insert (p, 3); p = insert (p, 4); p = insert (p, 2); traverse (p); 6

7. Suppose you are given the following Makefile. CFLAGS=-A CC=lcc main: main.o stat.o freq.o store.o list.o table.o $(CC) $(CFLAGS) -o main main.o stat.o freq.o store.o list.o table.o main.o: main.c $(CC) $(CFLAGS) -c main.c stat.o: stat.c freq.h $(CC) $(CFLAGS) -c stat.c freq.o: freq.c list.h $(CC) $(CFLAGS) -c freq.c store.o: store.c table.h list.h $(CC) $(CFLAGS) -c store.c list.o: list.c list.h $(CC) $(CFLAGS) -c list.c table.o: table.c table.h $(CC) $(CFLAGS) -c table.c (a) Draw a diagram showing the dependencies between the modules. (b) What is the output of the following commands within the Unix shell? Assume the commands are invoked in the directory where all compiled modules and source files are located, and all programs compile without error or warning messages. touch main.c make touch freq.h rm -f main.o rm -f list.o rm -f *.o (c) What impact does adding a new local function to list.c have on other modules? 7