CSC209H5 Midterm: CSC209H UTM Test Fall12s Solution 274

91 views17 pages
31 Jan 2019
School
Course
Professor

Document Summary

All of the code fragments below compile but many of them have something wrong. Check the appropriate box to indicate whether or not there is a problem and provide an explanation. There are no marks for checking something is wrong without an explanation. Explanation: solution: /* assigning to string without enough space for null terminator */ Explanation: solution: /* derefercing a pointer before pointing to anything */ [1 mark] char * hobby = "running"; hobby[0] = "s"; Explanation: solution: /* assigning to a string in read-only memory */ [1 mark] char fullname[30] = "frederick"; fullname[4] = "\0"; Explanation: solution: /* nothing wrong - can assign a null-terminator to shorten a string */ [1 mark] char postal[6] = "m4a"; strncat(postal, "3k5", 4); Explanation: solution: /* strncat without enough space */ [1 mark] int j; int x[5] = {4,2,7,8,9}; for (j = 0; j <= 5; j++) { fprintf("%d\n", x[j]); Explanation: solution: accessing array elements beyond the end */

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents