comp206_midterm_sol

comp206_midterm_sol - 308-206B Midterm1Student Name:Student...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 308-206B Midterm1Student Name:Student Number:Midterm Examination308-206B 2001: Introduction to Software SystemsExaminer: Prof. Hans VangheluweThursday, February 15th, 2001Invigilators: Jan Prawdzik, Atir Syed, Salman Zafar, Viqas Zafar16:00 – 17:30INSTRUCTIONS:1. Answer all questions directly on the examination paper.2. Use the back of the last page as scrap (it will be ignored during grading).3. No aids of whatever type are permitted.4. The exam has 11 questions on 6 pages (including cover page).5. Attempt all questions: partial marks are given for incomplete but correct answers.6. Numbers between brackets denote the weight of each question. The total is 50 points.Good luck !308-206B Midterm2(1) [2]What gets printed if the following code fragment is run ?int i=5;int j=6;if (i = j)printf("First\n");elseprintf("Second\n");Solution:(i = j) assigns the value of j to i.The result of the assignmenti = jis the value of the Left Hand Side (LHS).(note: this is NOT i == j, the equality test)In a C condition, 0 stands for FALSE, anynon-zero condition stands for TRUE.The result is that "First\n" is printed(newline at the end).(2) [4]Given the declarationchar s = "Good\tluck\\%%\n";What is the length of strings(as returned bystrlen(s))?Solution:’\t’ is a single character’\\’ is a single character(printed as a single \, the escape character)’%’is a single character%% is interpreted by printf() as a single %as part of a string, each % counts as a single character however’\n’ is a single characterThus, the lengtsh of s is 13What is the return value ofstrlen(s)after the next statement has been executed ?s[strlen(s)/2] = ’\0’;308-206B Midterm3Solution:strlen(s)/2 = 13/2This is an integer division with result 6s[6] = ’\0’ gives a string of length 6(s[0] ... s[5])(3) [5]Assume the variablenamehas been declared as a character vector of appropriate size. Assume a valid C stringis present inname. Write a code fragment to reverse the string (of any length)....
View Full Document

This note was uploaded on 12/01/2009 for the course COMP COMP 206 taught by Professor Vybihal during the Winter '04 term at McGill.

Page1 / 9

comp206_midterm_sol - 308-206B Midterm1Student Name:Student...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online