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

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

SOFTWARE Ph.D. Qualifying Exam Fall 2017

COMP1917 Computing 1 Written Exam Sample Questions

ECE264 Spring 2013 Final Exam, April 30, 2013

CS61, Fall 2012 Section 2 Notes

Arrays and Strings. Antonio Carzaniga. February 23, Faculty of Informatics Università della Svizzera italiana Antonio Carzaniga

return return else return

Lecture 9 Assertions and Error Handling CS240

Class Information ANNOUCEMENTS

Signature: ECE 551 Midterm Exam

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

ENCM 339 Fall 2017 Tutorial for Week 8

ECE264 Fall 2013 Exam 3, November 20, 2013

ECE264 Fall 2013 Exam 2, October 24, 2013

1 SAT-DANCE-HEULE INTRO 1

ECE264 Spring 2014 Exam 2, March 11, 2014

Solution for Data Structure

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

CS 61c: Great Ideas in Computer Architecture

ECE264 Summer 2013 Exam 1, June 20, 2013

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

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

Arrays Arrays and pointers Loops and performance Array comparison Strings. John Edgar 2

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

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

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

Structures, Unions Alignment, Padding, Bit Fields Access, Initialization Compound Literals Opaque Structures Summary. Structures

Warmup January 9th, What is the value of the following C expression? 8*9 % 10/ 2

C LANGUAGE A Short Course

ECE264 Spring 2013 Exam 1, February 14, 2013

Q1: /8 Q2: /30 Q3: /30 Q4: /32. Total: /100

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

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

Foundation Exam - Sample Problems for New Topics

PROGRAMMAZIONE I A.A. 2017/2018

else return for return

NYU SCPS X Section 1 Unix System Calls. Fall 2004 Handout 8. Source code on the Web at mm64/x /src/doubly2.

EECE.2160: ECE Application Programming Spring 2018

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

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

Dynamic memory. EECS 211 Winter 2019

Arrays and Pointers in C. Alan L. Cox

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

Arrays, Strings, & Pointers

ECE264 Fall 2013 Exam 1, September 24, 2013

Slides adopted from T. Ferguson Spring 2016

Lab 3. Pointers Programming Lab (Using C) XU Silei

Archivo: /home/young/work/cordic/mvr_exhaustive.c Página 1 de 6

Programming in C - Part 2

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

ECE551 Midterm Version 1

Midterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

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

EL2310 Scientific Programming

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Pointers. Pointer Variables. Chapter 11. Pointer Variables. Pointer Variables. Pointer Variables. Declaring Pointer Variables

Kurt Schmidt. October 30, 2018

The output will be: marks all or nothing. 1 #include <stdio.h> 2 main() { 3 int i; int j; 4 int *p; int *q; 6 p = &i; 7 q = &j; 8 i = 1;

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

ESC101N: Fundamentals of Computing End-sem st semester

C Language Advanced Concepts. Microcomputer Architecture and Interfacing Colorado School of Mines Professor William Hoff

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

Binary Search Tree 1.0. Generated by Doxygen Mon Jun :12:39

ECE 2400 Computer Systems Programming Fall 2017 Topic 4: C Pointers

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

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

Linked Lists. .. and other linked structures. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Binary Representation. Decimal Representation. Hexadecimal Representation. Binary to Hexadecimal

Decimal Representation

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

Programming. Pointers, Multi-dimensional Arrays and Memory Management

Variation of Pointers

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.

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

ECE551 Midterm Version 2

Advanced Pointer Topics

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

PROGRAMMAZIONE I A.A. 2017/2018

Faculty of Applied Science and Engineering, University of Toronto CSC181: Introduction to Computer Programming, Fall 2000

COP 3502 Section 2 Exam #2 Version A Spring /23/2017

Jagannath Institute of Management Sciences Lajpat Nagar. BCA II Sem. C Programming

Singly linked lists in C.

C Sample Code. Nyoman Bogi Aditya Karna Sisfo IMTelkom

CS Programming In C

C Pointers. 7.2 Pointer Variable Definitions and Initialization

C Syntax Arrays and Loops Math Strings Structures Pointers File I/O. Final Review CS Prof. Jonathan Ventura. Prof. Jonathan Ventura Final Review

C Programming Language: C ADTs, 2d Dynamic Allocation. Math 230 Assembly Language Programming (Computer Organization) Thursday Jan 31, 2008

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

15 122: Principles of Imperative Computation. Practice Exam August 4, 2015

Iteration. Side effects

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

Linked Data Representations

Midterm #2 CISC 220, Winter 2008

FORM 2 (Please put your name and form # on the scantron!!!!)

Computer Hardware Engineering

Final Intro to C Review

BBM 201 DATA STRUCTURES

Procedural programming with C

Dynamic Memory Management. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

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

Transcription:

(i) (6 pts.) SOFTWARE Ph.D. Qualifying Exam Spring 2017 Consider the following C program, which includes three function definitions, including the main function. #include <stdio.h> #include <string.h> void g(char *x) { int length = strlen(x); char *p = NULL; if (length!= 0) { printf("%c\n", x[0]); p = &(x[2]); g(p); void f(char a[], int x, int *y) { x = x + (*y); a[x] = '\0'; a[x + 1] = '\0'; (*y)++; g(a); int main(void) { char s[] = "Maryland"; int x1 = 4; int x2 = 2; printf("s = %s, x1 = %d, x2 = %d\n", s, x1, x2); f(s, x1, &x2); printf("s = %s, x1 = %d, x2 = %d\n", s, x1, x2); 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) (4 pts.) Consider the following C program. #include <stdio.h> #include <ctype.h> void display_result(int result) { static int index = 1; printf("result #%d: %d\n", index++, result); int main(void) { char *s = "123xyz456abc", *p = s; int x = 0, iterations = 0, i = 0; const int step = 3, lim1 = 20, lim2 = 63, param1 = 4; for (i = 0; i <= lim1; i += step) { x = lim2; while (x > 0) { x = x / param1; for (i = 17; i > 3; i--) { i -= 2; while (!(isalpha(*p))) { p++; for (i = 10; (i + iterations) < 20; i++) { if ((i % 3) == 0) { iterations += 2; else { 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 previous page.

(iii) (6 pts.) Consider the following C program, which includes three function definitions, including the main function shown on the following page. #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct elem { int data; struct elem *next; struct elem *prev; elem; void insert(elem **h, elem *e) { e->next = (*h); (*h)->prev = e; (*h) = e; e->prev = NULL; elem *get(elem *h, char *config) { elem *p = h; int length = strlen(config), i = 0; for (i = 0; i < length; i++) { if (p == NULL) { fprintf(stderr, "invalid access\n"); exit(1); if (config[i] == '+') { p = p->next; else if (config[i] == '/') { p = p->prev; return p;

int main(void) { elem a = {5, NULL, NULL; elem *b = NULL; elem *head = &a; int data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0; int i = 0; const int len = 10, factor = 7, insertions = 6; for (i = 0; i < insertions; i++) { b = malloc(sizeof(elem)); b->data = data[(i * factor) % len]; printf("inserting: %d\n", b->data); insert(&head, b); b = get(head, "+aa/++"); printf("<%d>\n", b->data); b = get(b, "/x+y/"); printf("<%d>\n", b->data); b = get(b, "zz++/+/z++"); printf("<%d>\n", b->data); 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 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.

(iv) (4 pts.) Consider the following string of if-else statements if (c == '+') { result = x1 + x2; else if (c == '-') { result = x1 - x2; else if (c == '*') { result = x1 * x2; else { result = 0; Write a new version of this code segment that has the same functionality but uses a switch statement instead of if-else for the required program selection operations. Show all work, and clearly indicate your solution. Show your work and your solution for this problem only on the 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 2017 Dept. of ECE, University of Maryland, College Park 11/20/2016 Problem 1: s = Maryland, x1 = 4, x2 = 2 M r l s = Maryla, x1 = 4, x2 = 3 Problem 2: result #1: 7 result #2: 3 result #3: 5 result #4: 3 result #5: 6 Problem 3: inserting: 1 inserting: 8 inserting: 5 inserting: 2 inserting: 9 inserting: 6 <2> <9> <8> Problem 4: switch (c) { case '+': result = x1 + x2; break; case '-': result = x1 - x2; break; case '*': result = x1 * x2; break; default: result = 0; break;