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

Similar documents
SOFTWARE Ph.D. Qualifying Exam Spring Consider the following C program, which includes three function definitions, including the main function.

SOFTWARE Ph.D. Qualifying Exam Fall 2017

Array Initialization

... Lecture 12. Pointers

Approximately a Final Exam CPSC 206

COMP1917 Computing 1 Written Exam Sample Questions

Dynamic memory. EECS 211 Winter 2019

ECE264 Spring 2013 Final Exam, April 30, 2013

Class Information ANNOUCEMENTS

C LANGUAGE A Short Course

Slide Set 4. for ENCM 339 Fall 2017 Section 01. Steve Norman, PhD, PEng

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

Approximately a Test II CPSC 206

Arrays, Strings, & Pointers

Arrays and Pointers in C. Alan L. Cox

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

CS360 Midterm 1 - February 21, James S. Plank. Put all answers on the answer sheet. In all of these questions, please assume the following:

ENCM 339 Fall 2017 Tutorial for Week 8

ECE264 Fall 2013 Exam 3, November 20, 2013

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

CS 61c: Great Ideas in Computer Architecture

Arrays and Pointers (part 2) Be extra careful with pointers!

Final Intro to C Review

Course organization. Course introduction ( Week 1)

Arrays and Pointers (part 2) Be extra careful with pointers!

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

CMPSC 311- Introduction to Systems Programming Module: Arrays and Pointers

Solution for Data Structure

COP 3223 Introduction to Programming with C - Study Union - Spring 2018

CS 61C: Great Ideas in Computer Architecture. C Arrays, Strings, More Pointers

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

ECE551 Midterm. There are 7 questions, with the point values as shown below. You have 75 minutes with a total of 75 points. Pace yourself accordingly.

Language comparison. C has pointers. Java has references. C++ has pointers and references

CS 0449 Sample Midterm

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

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

8. Characters, Strings and Files

ECE264 Fall 2013 Exam 1, September 24, 2013

CSI 402 Lecture 2 Working with Files (Text and Binary)

Example: Pointer Basics

CS 33. Introduction to C. Part 5. CS33 Intro to Computer Systems V 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

Variation of Pointers

File: /media/young/d1 (180713)/Work tive_tree_search/search_defs.h Page 1 of 1

upper and lower case English letters: A-Z and a-z digits: 0-9 common punctuation symbols special non-printing characters: e.g newline and space.

Bil 104 Intiroduction To Scientific And Engineering Computing. Lecture 7

Pointers. Memory. void foo() { }//return

CS61, Fall 2012 Section 2 Notes

These problems are provided to you as a guide for practice. The questions cover important concepts covered in class.

ECE264 Summer 2013 Exam 1, June 20, 2013

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

C Pointers. CS 2060 Week 6. Prof. Jonathan Ventura

CSE 303 Winter 2008 Midterm Key

M.CS201 Programming language

CS , Fall 2003 Exam 2

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

Algorithms & Programming. Midterm Examination # 2. Student Name: Student ID Number: Duration of examination:

Syntax Analysis Part VIII

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

Archivo: /home/young/work/cordic/binary_tree_search/search_defs.h Página 1 de 1

Chapter 2 (Dynamic variable (i.e. pointer), Static variable)

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

C PROGRAMMING Lecture 4. 1st semester

Memory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables)

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

Q1: /20 Q2: /30 Q3: /24 Q4: /26. Total: /100

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

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

CSC209H1S Day Midterm Solutions Winter 2010

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

ECE264 Fall 2013 Exam 2, October 24, 2013

ECE264 Spring 2013 Exam 1, February 14, 2013

Introduction to Data Structures. Systems Programming

return return else return

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Programming Language B

COMS Spring Homework 3

Why Pointers. Pointers. Pointer Declaration. Two Pointer Operators. What Are Pointers? Memory address POINTERVariable Contents ...

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

Fundamental of Programming (C)

Princeton University COS 333: Advanced Programming Techniques A Subset of C90

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)

This is CS50. Harvard University Fall Quiz 0 Answer Key

Advanced Pointer Topics

CSE 333 Lecture 3 - arrays, memory, pointers

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

POINTER & REFERENCE VARIABLES

Foundation Exam - Sample Problems for New Topics

공학프로그래밍언어 (PROGRAMMING LANGUAGE FOR ENGINEERS) -STRUCTURE- SPRING 2015 SEON-JU AHN, CNU EE

Slide Set 4. for ENCM 335 in Fall Steve Norman, PhD, PEng

Quiz 0 Answer Key. Answers other than the below may be possible. Multiple Choice. 0. a 1. a 2. b 3. c 4. b 5. d. True or False.

Lecture 04 Introduction to pointers

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

Introduction to C: Pointers

Singly linked lists in C.

Signature: ECE 551 Midterm Exam

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

PRINCIPLES OF OPERATING SYSTEMS

Arrays and Pointers. CSE 2031 Fall November 11, 2013

ECE 15B COMPUTER ORGANIZATION

Question 1. Part (a) [2 marks] error: assignment of read-only variable x ( x = 20 tries to modify a constant) Part (b) [1 mark]

Transcription:

(i) (5 pts.) SOFTWARE Ph.D. Qualifying Exam Spring 2018 Consider the following C program which consists of two function definitions including the main function. #include <stdio.h> int g(int z) { int y = 0; const int k = 3; printf("z = %d\n", z); if (z <= 0) { return k * (z + 2); else { y = g(z - 1) + g(z - 2); return y; int main(void) { int arg = 3; int result = 0; result = g(arg); printf("result = %d\n", result); return 0; Show the complete output as it appears on standard output. Show all work, and clearly indicate your solution. Show your work and your solution for this problem only on this page and (if more space is needed) the next page. In case of an illegal dereferencing of a pointer (e.g., dereferencing of an uninitialized pointer, null pointer, or pointer that goes beyond the boundaries of an array), show all of the output from the printf calls that are executed up to the point just before the illegal pointer dereference, and then write "illegal pointer operation" on the following line.

This page is reserved as extra space for working on and writing your solution to Question (i).

(ii) (6 pts.) Consider the following C program, which consists of three function definitions including the main function. #include <stdio.h> #include <stdlib.h> #define LEN 9 #define OFFSET 5 typedef struct node { int val; struct node *next; node; void insert_one(node **h, node *e) { int v = e->val; node *p = NULL; if (v < -1) { e->next = (*h)->next->next; (*h)->next->next = e; else if (v > 1) { e->next = (*h); (*h) = e; else { for (p = (*h); p->next!= NULL; p = p->next); e->next = p->next; p->next = e; void show_all(node *h) { node *p = NULL; for (p = h; p!= NULL; p = p->next) { printf("<%d>", p->val); printf("\n");

int main(void) { node n1 = {7, NULL; node n2 = {3, &n1; node n3 = {5, &n2; node *h = &n3; int values[] = {7, -4, 9, -1, 0, 0, 7, -8, 12; int i = 0; node *new = NULL; show_all(h); show_all(&n1); for (i = 0; i < LEN; i+=2) { new = malloc(sizeof(node)); new->val = values[(i + OFFSET) % LEN]; insert_one(&h, new); show_all(h); show_all(&n2); Show the complete output as it appears on standard output. Show all work, and clearly indicate your solution. Show your work and your solution for this problem only on this page and (if more space is needed) the previous page. In case of an illegal dereferencing of a pointer (e.g., dereferencing of an uninitialized pointer, null pointer, or pointer that goes beyond the boundaries of an array), show all of the output from the printf calls that are executed up to the point just before the illegal pointer dereference, and then write "illegal pointer operation" on the following line.

(iii) (5 pts.) Consider the following C program. #include <stdio.h> #include <string.h> #include <ctype.h> #define SIZE 10 int main(void) { char src1[] = "xya$%fsp\\my"; char src2[] = "\\m%psdf22nnz"; char dst[size] = "123456789"; int i = 0; const int stride = 2; for (i = 0; i < SIZE; i += stride) { if (isalpha(src1[i])) { dst[i] = src2[i]; else { dst[i] = src1[i]; src1[i] = '\0'; printf("%s\n", dst); printf("len1 = %d\n", (int)(strlen(src1))); printf("len2 = %d\n", (int)(strlen(src2))); return 0; Show the complete output as it appears on standard output. Show all work, and clearly indicate your solution. Show your work and your solution for this problem only on this page and (if more space is needed) the next page. In case of an illegal dereferencing of a pointer (e.g., dereferencing of an uninitialized pointer, null pointer, or pointer that goes beyond the boundaries of an array), show all of the output from the printf calls that are executed up to the point just before the illegal pointer dereference, and then write "illegal pointer operation" on the following line.

This page is reserved as extra space for working on and writing your solution to Question (iii).

(iv) (4 pts.) For this problem, we define the set of valid text characters as the set that consists of (1) all alphabetic characters (lower case and upper case), (2) all characters that correspond to decimal digits (0-9), (3) the space character, and (4) the underscore character. Write a C program that inputs a line of text from standard input, and prints the line to standard output with all of the nonvalid text characters filtered out (removed). For example, if the input line is Hello ^_^ How Are You? then the output would be Hello _ How Are You Write the program to handle an input line that has at most 100 characters. If the input line has more than 100 characters, then print a meaningful error message to standard error and exit without printing anything to standard output. Use the putc utility to read the input text from standard input. Show your work and your solution for this problem only on this page, and (if more space is needed) the next page.

This page is reserved as extra space for working on and writing your solution to Question (iv).

Software Qualifying Exam Solutions Spring 2018 Dept. of ECE, University of Maryland, College Park 11/20/2018 Problem 1: z = 3 z = 2 z = 1 z = 0 z = -1 z = 0 z = 1 z = 0 z = -1 result = 24 Problem 2: <5><3><7> <7> <9><7><5><3><-8><7><0><0> <3><-8><7><0><0> Problem 3: \2%4%6f8\ len1 = 4 len2 = 12

Problem 4: #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> #define MAXLEN 100 int main(void) { char line[maxlen + 1]; int i = -1; char c = '\0'; int done = 0; while (!done) { c = getc(stdin); if ((c == EOF) (c == '\n')) { done = 1; else { i++; if (i >= MAXLEN) { fprintf(stderr, "Line too long\n"); exit(1); else { line[i] = c; line[++i] = '\0'; for (i = 0; i < strlen(line); i++) { c = line[i]; if (isalpha(c) isdigit(c) (c == ' ') (c == '_')) { printf("%c", c); printf("\n"); return 0;