This%is%CS50.% Harvard*University*Fall%2013* Quiz*0* out*of*84*points* Print*your*name*on*the*line*below.* % % % % % % % % % % %
|
|
- Ferdinand Asher Wiggins
- 5 years ago
- Views:
Transcription
1 ThisisCS50. HarvardUniversityFall2013 Quiz0 outof84points Printyournameonthelinebelow. Donotturnthispageoveruntiltoldbythestafftodoso. Thisquizis"closedBbook."However,youmayutilizeduringthequizonetwoBsided page(8.5" 11")ofnotes,typedorwritten,andapenorpencil,nothingelse. Scrappaperisincludedatthisdocument'send. Unlessotherwisenoted,youmaycallanyfunctionswe'veencounteredthistermincodethatyouwrite. Youneedn'tcommentcodethatyouwrite,butcommentsmayhelpincasesofpartialcredit. Ifrunningshortontime,youmayresorttopseudocodeforpotentialpartialcredit. AlisaNguyen Circleyourteachingfellow'sname. R.J.Aquino Allison BuchholtzBAu AngelaLi ArmaghanBehlum BenShryock BoNingHan CaseyGrun ChiZeng Christopher Bartholomew DiannaHu DougLloyd EdHebert GabrielGuimaraes GeorgeWu HannahBlumberg IanNightingale JacksonSteinkamp JaredPochtar JulianSalazar KarenXiao KatrynaCadle KeenanMonks KendallSherman KevinMu KevinSchmid LeviRoth LucasFreitas RhedShi RobBowden RogerZurawicki RyanLee SaheelaIbraheem SharonZhou TimMcLaughlin TomasReimers TravisDowns ChrisMueller JasonHirschhorn LucianoArango TylerMorrison CynthiaMeng JoeMcCormick LucyCheng VarunSriram DanBradley JonathanMarks LydiaChen WesleyChen DavenFarnham JonathanMiller MarshallZhang WilliamHakim DavidKaufman JordanJozwiak MikeRizzo WilliamXiao JosephOng PatrickSchmid ZamylaChan 0<19
2 ThisisCS50. HarvardUniversityFall2013 forstaffuseonly! final!score!out!of!84! 1<19
3 ThisisCS50. HarvardUniversityFall2013 MultipleChoice. Foreachofthefollowingquestions,circletheletter(a,b,c,ord)oftheoneresponsethatbestanswers thequestion;youneednotexplainyouranswers. 0. (1point.)Howmanydesklampsdoyouneedtorepresentthedecimalnumber7inbinary? a. 2 b. 3 c. log 2 7 d (1point.)Howmanytimescanyoutearaphonebookwith128pages(i.e.,sheetsofpaper)inhalf, eachtimethrowingawayoneofthehalves,beforeonlyonepageremains? a. 6 b. 7 c. 10 d. 64 O(MG). 2. (5 points.) Complete the table below by specifying lower (Ω) and upper (O) bounds on each algorithm'srunningtime.assumethattheinputtoeachalgorithmisanarrayofsizen.we've plucked off two cells for you. For the curious, Bogo Sort (otherwise known as Stupid Sort) randomly orders an array, checks if it's sorted, and repeatedly tries again if it's not. More formally,"itservesasasortofcanonicalexampleofawfulness." Ω O BogoSort n# BubbleSort # InsertionSort # LinearSearch # MergeSort # SelectionSort # forstaffuseonly 2<19
4 ThisisCS50. HarvardUniversityFall2013 Phew,Scratch. 3. (4points.)ConsidertheScratchscriptbelow. Inthespacebelow,translatethescriptintoaCprogramthat'sfunctionallythesame(albeitina commandzlineenvironment);itneedn'tbestructurallythesame.assumethatscratch'ssayblock translatestoprintfinc,thoughanycalltoprintfshouldincludeatrailing\n.andrecallthat changenbye1meanstodecrementnby1. forstaffuseonly 3<19
5 ThisisCS50. HarvardUniversityFall (4points.)ConsidertheScratchscriptsbelow. Inthespacebelow,translatethescriptsintoaCprogramwithtwofunctions,mainandcough, that'sfunctionallythesame(albeitinacommandzlineenvironment);itneedn'tbestructurallythe same. Assume that Scratch's say block translates to printf in C, though any call to printf shouldincludeatrailing\n. forstaffuseonly 4<19
6 ThisisCS50. HarvardUniversityFall2013 ItsaMarioagain. 5. (4 points.) Toward the end of World 2Z3 in Nintendo's Super Mario Brothers 3, Mario must descenda"halfzpyramid"ofblocks(unlesshefliesoverit).belowisascreenshot. Completetheimplementationoftheprogrambelowinsuchawaythatitrecreatesthisparticular halfzpyramidusinghashes(#) for blocks. Noneedforuserinput;youmayhardZcode the halfz pyramid'sheight(7)intoyourprogram. forstaffuseonly 5<19
7 ThisisCS50. HarvardUniversityFall2013 CS50Library (6points.)Considertheprogram,positive,below. #include <cs50.h> printf("positive integer please: "); int n = GetPositiveInt(); printf("thanks for the i!\n", n); Consider how this program and, in turn, GetPositiveInt are meant to behave, as per the below,whereinunderlinedtextrepresentssomeuser'sinput. jharvard@appliance (~/Dropbox/quiz0):./positive Positive integer please: -50 Retry: 0 Retry: 50 Thanks for the 50! IfonlyGetPositiveIntactuallyexisted!Supposethatyou'dliketoimplementitforusforthe nextversionofthecs50library.completetheimplementationofgetpositiveintbelowusing GetInt(whichdoesexist!)insuchawaythattheprogramabovewouldindeedbehaveperthe inputandoutputabove.notethatit'smain,notgetpositiveint,that'spromptingtheuser withpositive integer please:.andbesurethatgetpositiveintonlypromptstheuser withretry:iftheuserfailstoprovideapositiveinteger. int GetPositiveInt(void) forstaffuseonly 6<19
8 ThisisCS50. HarvardUniversityFall (4points.)Considertheprogram,random,below. #include <cs50.h> int n = RandomInt(0, 50); printf("here's a i!\n", n); Consider how this program and, in turn, RandomInt are meant to behave, as per the below, whereinunderlinedtextrepresentssomeuser'sinput. jharvard@appliance (~/Dropbox/quiz0):./random Here's a 42! IfonlyRandomIntactuallyexisted!Supposethatyou'dliketoimplementitforusforthenext versionofthecs50library.completetheimplementationofrandomintbelowinsuchaway that, given a and b, the function returns a pseudorandom integer between a (inclusive) and b (exclusive) using drand48. Recall that drand48 returns "nonnegative doublezprecision floatingzpointvaluesuniformlydistributedbetween"0.0(inclusive)and1.0(exclusive).youmay assumethatbwillbegreaterthana.andyoumayassumeboththatsrand48hasalreadybeen calledforyouelsewhereandthatstdlib.h(inwhichdrand48andsrand48aredeclared)has been#include'dforyouelsewhere(andthat_xopen_sourceis#define'dasneeded). int RandomInt(int a, int b) forstaffuseonly 7<19
9 ThisisCS50. HarvardUniversityFall2013 Swapfest. 8. (6points.)Considertheprogrambelow,betweenwhoselinessomenumberedarrowshavebeen drawnforthesakeofdiscussion. void swap(int a, int b) 3! int tmp = a; 4! a = b; 5! b = tmp; 6! int x = 1; 1! int y = 2; 2! swap(&x, &y); 7! Supposethateachofthenumberedarrowsrepresentsamomentintimeduringthisprogram's execution.andsupposethat &x(i.e.,theaddressof x)is 0x123andthat&y(i.e.,theaddress ofy)is0x127. Recordintheblankboxesbelowthevaluesinscopeateachmomentintime.Forinstance,ifthe program'sexecutionispausedatnumberedarrow2,thevalueofxwouldbe1,andthevalueofy wouldbe2.boxesforvaluesnotinscopehavebeenblackedout.keepinmindthatarepresents thevalueina,whilearepresentsthevalueata.thesameholdsforbandb. x y a a b b tmp 1! 1 2! 1 2 3! 4! 1 5! 6! " 7! 2 1 forstaffuseonly 8<19
10 ThisisCS50. HarvardUniversityFall (5points.)Considerthesimilar,butdifferent,programbelow,betweentwoofwhoselinesjust one numbered arrow has been drawn for the sake of discussion, albeit numbered 6 for consistency. void swap(int a, int b) int tmp = a; a = b; b = tmp; 6! int x = 1; int y = 2; swap(x, y); Supposethatthisprogram'sexecutionispausedatnumberedarrow6andthatthediagrambelow represents the program's stack frames at that moment. Record in the blank boxes below the valuesofx,y,a,b,andtmpatthatmoment.(recallthat,eventhoughxandyareoutofscope, theystillexistinmemory.) swap a b tmp main x y " " forstaffuseonly 9<19
11 ThisisCS50. HarvardUniversityFall2013 #include? 10. (6points.)Supposethatyou'veforgottenwhichheaderfiledeclaresatoi,andsoyouneedto rezimplementityourself.argh.withoutcallinganyfunctionsotherthanstrlen(whichyoumay callifyou'dlike),completetheimplementationofatoibelowinsuchawaythatitconvertss (e.g.,"123")toanint(e.g.,123).ifshappenstobenull,orifscontainsanycharacterthat isn't '0' through '9', your implementation of atoi should return 0.Otherwise, you may assumethatsrepresentsanonznegativeintegerthat,whenconverted,willfitinsideofanint withoutoverflow.noneedto#includeanyfiles(evenifyoucallstrlen). int atoi(char s) forstaffuseonly 10<19
12 ThisisCS50. HarvardUniversityFall (6 points.) Suppose that you've also forgotten which header file declares strlen, and so you needtorezimplementityourself(evenifyoudidn'tjustuseit).bah.evenworse,neither[nor] currently works on your keyboard (or pencil or pen). Without calling any functions at all and without using any square brackets, complete the implementation of strlen below usingpointerarithmeticinsuchawaythatthefunctionreturnsthelengthofs.ifshappenstobe NULL,yourimplementationofstrlenshouldreturn0. int strlen(char s) forstaffuseonly 11<19
13 ThisisCS50. HarvardUniversityFall2013 Switchinggears. 12. (4points.)Considertheprogrambelow. #include <cs50.h> int n = GetInt(); switch (n) case 1: case 2: printf("small\n"); break; case 3: printf("medium\n"); break; case 4: case 5: printf("large\n"); break; CompletethereZimplementationofthisprogrambelowwithoutusingswitchinsuchawaythat itstillbehavesexactlythesame. #include <cs50.h> int n = GetInt(); forstaffuseonly 12<19
14 ThisisCS50. HarvardUniversityFall2013 Didyoumean:recursion. Considertheprogrambelow. #include <cs50.h> int sigma(int m) printf("i", m); if (m == 0) printf("="); return 0; else printf("+"); return (m + sigma(m - 1)); int n = GetInt(); int answer = sigma(n); printf("i\n", answer); 13. (2points.)Supposethatauserrunsthisprogram,inputting5(followedbyEnter)whenprompted bygetint.exactlywhatdoestheprogramprintbeforeexiting? 14. (2points.)Supposethatauserrunsthisprogram,inputtinganegativevaluelike-5(followedby Enter)whenpromptedbyGetInt.Whymighttheprogramsegfault? " forstaffuseonly 13<19
15 ThisisCS50. HarvardUniversityFall2013 Thisisnot (2points.)Convertthebinarynumberbelowtodecimal.Showanywork(i.e.,anyarithmetic) Makingprogress. 16. (4points.)Considerthesourcecodebelow. #include <cs50.h> string s = GetString(); printf("hello, s\n", s); Recall that the process of "compiling" this source code into an executable program via make actuallyinvolvesfourdistinctphases,thoughnotnecessarilyinthisorder:assembling,compiling, linking,andpreprocessing.withrespecttothisprogram,describewhathappensduringeachof thosephases,inatleastonesentenceperphase,intheorderinwhichthosephasesoccur. forstaffuseonly 14<19
16 ThisisCS50. HarvardUniversityFall2013 Makingsense. 17. (2points.)Considertheprogrambelow. int cents = 50; float dollars = cents / 100; printf(".2f\n", dollars); Whenexecuted,thisprogramprints 0.00 which is not how much money we have! In no more than three sentences, explain why this program thinks that 50 cents divided by 100, printed to 2 decimal places, is something otherthan (2points.)Considertheprogram,think,below. #include <string.h> int main(int argc, char argv[]) for (int i = 0, n = strlen(argv[0]); i < n; i++) printf("c", argv[0][i]); Supposethatthisprogramisexecutedasfollows../think twice Exactlywhatwouldbeprinted? forstaffuseonly 15<19
17 ThisisCS50. HarvardUniversityFall2013 Shortanswers.(2pointseach.) Answereachofthequestionsbelowinnomorethanthreesentences. 19. WhyisSelectionSort'srunningtimeinΩ(n 2 )evenwhenitsinputisalreadysorted? 20. InwhatsensehavewebeenleakingmemorywhenusingGetString(atleastinmostlectures)? 21. Whensomealgorithmcouldbeimplementedincodeeitheriterativelyorrecursively,whymight youwanttoimplementitrecursively? 22. Whensomealgorithmcouldbeimplementedincodeeitheriterativelyorrecursively,whymight youwanttoimplementititeratively? 23. InwhatsenseisVigenère'sciphermoresecurethanCaesar'scipher? forstaffuseonly 16<19
18 ThisisCS50. HarvardUniversityFall2013 Ponies. 24. (2points.)Supposethataclassmatehasjustsentyouthe message at right. Without seeing your classmate's code, proposewhatyourclassmatehasdonewrongandhowto fixit. 25. (2points.)Supposethatthesameclassmatehasjustsent youthemessageatright.withoutseeingyourclassmate's code, propose what your classmate has done wrong and howtofixit. 26. (0points.)Nowsupposethatyourclassmatehasjustsent youthemessageatright.d'aww. forstaffuseonly 17<19
19 ThisisCS50. HarvardUniversityFall2013 ScrapPaper. Nothing#on#this#page#will#be#examined#by#the#staff#unless#otherwise#directed.# # # # # # 18<19
20
This%is%CS50.% Harvard*University*Fall%2012* Quiz*1* out*of*121*points* Name* * * * * * * * * * * % % Harvard*ID*number* * * * * * * * * %
ThisisCS50. HarvardUniversityFall2012 Quiz1 outof121points Donotturnthispageoveruntiltoldbythestafftodoso. Thisquizis"closed@book."However,youmayutilizeduringthequizonetwo@sided page(8.5" 11")ofnotes,typedorwritten,andapenorpencil,nothingelse.
More informationThis%is%CS50.% Harvard*University*Fall%2014* Quiz*1* out*of*109*points* Print*your*name*on*the*line*below.* % % % % % % % % % % %
ThisisCS50. HarvardUniversityFall2014 Quiz1 outof109points Printyournameonthelinebelow. Donotturnthispageoveruntiltoldbythestafftodoso. Thisquizis"closedBbook."However,youmayutilizeduringthequizonetwoBsided
More informationThis is CS50. Harvard University Fall Quiz 0 Answer Key
Quiz 0 Answer Key Answers other than the below may be possible. Binary Bulbs. 0. Bit- Sized Questions. 1. Because 0 is non- negative, we need to set aside one pattern of bits (000) for it, which leaves
More informationWeek 4. This is CS50. Harvard University. Fall Anna Whitney
This is CS50. Harvard University. Fall 2015. Anna Whitney Table of Contents 1. Volkswagen and Trust in Software... 1 2. Recursion... 2 3. Sigma... 4 4. Swap... 8 5. Debugging with CS50 IDE... 11 6. Pointers...
More informationQuiz 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.
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. 6. T or F 7. T 8. F 9. T 10. T or F Itching for Week 0? 11. 00011001 + 00011001
More informationArray Basics: Outline. Creating and Accessing Arrays. Creating and Accessing Arrays. Arrays (Savitch, Chapter 7)
Array Basics: Outline Arrays (Savitch, Chapter 7) TOPICS Array Basics Arrays in Classes and Methods Programming with Arrays Searching and Sorting Arrays Multi-Dimensional Arrays Static Variables and Constants
More informationQuiz 0 Review Session. October 13th, 2014
Quiz 0 Review Session October 13th, 2014 Topics (non-exhaustive) Binary. ASCII. Algorithms. Pseudocode. Source code. Compiler. Object code. Scratch. Statements. Boolean expressions. Conditions. Loops.
More informationParameter passing. Programming in C. Important. Parameter passing... C implements call-by-value parameter passing. UVic SEng 265
Parameter passing Programming in C UVic SEng 265 Daniel M. German Department of Computer Science University of Victoria 1 SEng 265 dmgerman@uvic.ca C implements call-by-value parameter passing int a =
More informationreturn return else return
compare0.c 1 // Compares two strings' addresses 4 #include 5 6 int main(void) 7 { 8 // get two strings 9 string s = get_string("s: "); 10 string t = get_string("t: "); 11 1 // compare strings'
More informationelse return for return
addresses.c 1 // Prints two strings' addresses 4 #include 5 6 int main(void) 7 { 8 // Get two strings 9 string s = get_string("s: "); 10 string t = get_string("t: "); 11 1 // Print strings' addresses
More informationLecture 4: Outline. Arrays. I. Pointers II. III. Pointer arithmetic IV. Strings
Lecture 4: Outline I. Pointers A. Accessing data objects using pointers B. Type casting with pointers C. Difference with Java references D. Pointer pitfalls E. Use case II. Arrays A. Representation in
More informationPointers and scanf() Steven R. Bagley
Pointers and scanf() Steven R. Bagley Recap Programs are a series of statements Defined in functions Can call functions to alter program flow if statement can determine whether code gets run Loops can
More informationProblem 2 Add the two 2 s complement signed 8-bit values given below, and express your answer in decimal.
Problem 1 Recall the definition of root in project 1. (The declaration of struct entrynode appears below.) struct entrynode * root; Give the type of each of the following expressions. The answer may be
More informationG52CPP C++ Programming Lecture 3. Dr Jason Atkin
G52CPP C++ Programming Lecture 3 Dr Jason Atkin E-Mail: jaa@cs.nott.ac.uk 1 Revision so far C/C++ designed for speed, Java for catching errors Java hides a lot of the details (so can C++) Much of C, C++
More informationWeek 3. This is CS50. Harvard University. Fall Cheng Gong
This is CS50. Harvard University. Fall 2014. Cheng Gong Table of Contents Command-Line Arguments... 1 Memory Access... 5 Return Values... 6 More on argv... 8 Sorting... 10 Bubble Sort... 11 Selection Sort...
More informationFloating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions
Announcements Thursday Extras: CS Commons on Thursdays @ 4:00 pm but none next week No office hours next week Monday or Tuesday Reflections: when to use if/switch statements for/while statements Floating-point
More informationAt the end of this module, the student should be able to:
INTRODUCTION One feature of the C language which can t be found in some other languages is the ability to manipulate pointers. Simply stated, pointers are variables that store memory addresses. This is
More informationC BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.
C BOOTCAMP DAY 2 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Pointers 2 Pointers Pointers are an address in memory Includes variable addresses,
More informationare all acceptable. With the right compiler flags, Java/C++ style comments are also acceptable.
CMPS 12M Introduction to Data Structures Lab Lab Assignment 3 The purpose of this lab assignment is to introduce the C programming language, including standard input-output functions, command line arguments,
More informationBSM540 Basics of C Language
BSM540 Basics of C Language Chapter 4: Character strings & formatted I/O Prof. Manar Mohaisen Department of EEC Engineering Review of the Precedent Lecture To explain the input/output functions printf()
More informationLecture 04 Introduction to pointers
Lecture 04 Introduction to pointers A pointer is an address in the memory. One of the unique advantages of using C is that it provides direct access to a memory location through its address. A variable
More informationArray Initialization
Array Initialization Array declarations can specify initializations for the elements of the array: int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ; initializes primes[0] to 2, primes[1] to 3, primes[2]
More informationProgramming in C. UVic SEng 265. Daniel M. German Department of Computer Science University of Victoria. October 23, 2002 Version: 1.
Programming in C UVic SEng 265 Daniel M. German Department of Computer Science University of Victoria October 23, 2002 Version: 1.00 11 1 Programming in C (1.00) dmgerman@uvic.ca Parameter passing C implements
More informationComputer Science & Engineering 150A Problem Solving Using Computers
Computer Science & Engineering 150A Problem Solving Using Computers Lecture 06 - Stephen Scott Adapted from Christopher M. Bourke 1 / 30 Fall 2009 Chapter 8 8.1 Declaring and 8.2 Array Subscripts 8.3 Using
More informationsrc7-malan/c/array/array/main.c // main.c // Array // David J. Malan // Harvard University // // Demonstrates arrays. 11.
src7-malan/c/array/array/main.c 1 1 1 1 2 2 2 2 2 2 2 2 2 30. 3 3 3 main.c Array David J. Malan Harvard University malan@harvard.edu Demonstrates arrays. #include int main(int argc, const char
More informationArrays and Pointers in C. Alan L. Cox
Arrays and Pointers in C Alan L. Cox alc@rice.edu Objectives Be able to use arrays, pointers, and strings in C programs Be able to explain the representation of these data types at the machine level, including
More informationCGS 3460 Summer 07 Midterm Exam
Short Answer 3 Points Each 1. What would the unix command gcc somefile.c -o someotherfile.exe do? 2. Name two basic data types in C. 3. A pointer data type holds what piece of information? 4. This key
More informationLecture 16. Daily Puzzle. Functions II they re back and they re not happy. If it is raining at midnight - will we have sunny weather in 72 hours?
Lecture 16 Functions II they re back and they re not happy Daily Puzzle If it is raining at midnight - will we have sunny weather in 72 hours? function prototypes For the sake of logical clarity, the main()
More informationSample Examination. Family Name:... Other Names:... Signature:... Student Number:...
Family Name:... Other Names:... Signature:... Student Number:... THE UNIVERSITY OF NEW SOUTH WALES SCHOOL OF COMPUTER SCIENCE AND ENGINEERING Sample Examination COMP1917 Computing 1 EXAM DURATION: 2 HOURS
More informationWeek 1, continued. This is CS50. Harvard University. Fall Cheng Gong
This is CS50. Harvard University. Fall 2014. Cheng Gong Table of Contents Formula SAE at MIT... 1 Introduction... 1 C... 2 Functions and Syntax... 2 Compilers, Commands, and Libraries... 3 Conditions...
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationarrays and strings week 3 Ritsumeikan University College of Information Science and Engineering Ian Piumarta 1 / 22 imperative programming review
of char imperative week 3 and Ritsumeikan University College of Information Science and Engineering Ian Piumarta 1 / 22 : miscellaneous of char several library functions are have put or get in their name
More informationWeek 5, continued. This is CS50. Harvard University. Fall Cheng Gong
This is CS50. Harvard University. Fall 2014. Cheng Gong Table of Contents News... 1 Buffer Overflow... 1 Malloc... 6 Linked Lists... 7 Searching... 13 Inserting... 16 Removing... 19 News Good news everyone!
More informationOverview (1A) Young Won Lim 9/14/17
Overview (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationString constants. /* Demo: string constant */ #include <stdio.h> int main() {
Strings 1 String constants 2 /* Demo: string constant */ #include s1.c int main() { printf("hi\n"); } String constants are in double quotes A backslash \ is used to include 'special' characters,
More informationOverview (1A) Young Won Lim 9/9/17
Overview (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationMidterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009
Midterm Exam 2 Solutions C Programming Dr. Beeson, Spring 2009 April 16, 2009 Instructions: Please write your answers on the printed exam. Do not turn in any extra pages. No interactive electronic devices
More informationUNIVERSITY OF WINDSOR Fall 2007 QUIZ # 2 Solution. Examiner : Ritu Chaturvedi Dated :November 27th, Student Name: Student Number:
UNIVERSITY OF WINDSOR 60-106-01 Fall 2007 QUIZ # 2 Solution Examiner : Ritu Chaturvedi Dated :November 27th, 2007. Student Name: Student Number: INSTRUCTIONS (Please Read Carefully) No calculators allowed.
More informationSorting. Task Description. Selection Sort. Should we worry about speed?
Sorting Should we worry about speed? Task Description We have an array of n values in any order We need to have the array sorted in ascending or descending order of values 2 Selection Sort Select the smallest
More informationOverview (1A) Young Won Lim 9/25/17
Overview (1A) Copyright (c) 2009-2017 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later
More informationContents. A Review of C language. Visual C Visual C++ 6.0
A Review of C language C++ Object Oriented Programming Pei-yih Ting NTOU CS Modified from www.cse.cuhk.edu.hk/~csc2520/tuto/csc2520_tuto01.ppt 1 2 3 4 5 6 7 8 9 10 Double click 11 12 Compile a single source
More informationBIL 104E Introduction to Scientific and Engineering Computing. Lecture 14
BIL 104E Introduction to Scientific and Engineering Computing Lecture 14 Because each C program starts at its main() function, information is usually passed to the main() function via command-line arguments.
More informationTo declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows
Unti 4: C Arrays Arrays a kind of data structure that can store a fixed-size sequential collection of elements of the same type An array is used to store a collection of data, but it is often more useful
More information(Refer Slide Time: 00:23)
In this session, we will learn about one more fundamental data type in C. So, far we have seen ints and floats. Ints are supposed to represent integers and floats are supposed to represent real numbers.
More informationArrays and Pointers. CSE 2031 Fall November 11, 2013
Arrays and Pointers CSE 2031 Fall 2013 November 11, 2013 1 Arrays l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. 2 Arrays: Example
More informationChapter 16. Pointers and Arrays. Address vs. Value. Another Need for Addresses
Chapter 16 Pointers and Arrays Based on slides McGraw-Hill Additional material 200/2005 Lewis/Martin Pointers and Arrays We've seen examples of both of these in our LC- programs; now we'll see them in
More informationCS50 Supersection (for those less comfortable)
CS50 Supersection (for those less comfortable) Friday, September 8, 2017 3 4pm, Science Center C Maria Zlatkova, Doug Lloyd Today s Topics Setting up CS50 IDE Variables and Data Types Conditions Boolean
More informationCSE 333 Midterm Exam 2/12/16. Name UW ID#
Name UW ID# There are 6 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,
More informationLesson #8. Structures Linked Lists Command Line Arguments
Lesson #8 Structures Linked Lists Command Line Arguments Introduction to Structures Suppose we want to represent an atomic element. It contains multiple features that are of different types. So a single
More informationCSC 2400: Computer Systems. Arrays and Strings in C
CSC 2400: Computer Systems Arrays and Strings in C Lecture Overview Arrays! List of elements of the same type Strings! Array of characters ending in \0! Functions for manipulating strings 1 Arrays: C vs.
More informationEL2310 Scientific Programming
Lecture 11: Memory, Files and Bitoperations (yaseminb@kth.se) Overview Overview Lecture 11: Memory, Files and Bit operations Main function; reading and writing Bitwise Operations Lecture 11: Memory, Files
More informationLuar Topics. C A Low level Programming Language Make A dependency based build system YUYV Representation of Color ZMP Zero Moment Point control
Luar Topics C A Low level Programming Language Make A dependency based build system YUYV Representation of Color ZMP Zero Moment Point control C A Low level Programming Language Low level Compiles to machine
More informationObject oriented programming C++
http://uranchimeg.com Object oriented programming C++ T.Uranchimeg Prof. Dr. Email uranchimeg@must.edu.mn Power Engineering School M.EC203* -- OOP (C++) -- Lecture 06 Subjects Functions Functions with
More informationLecture 04 FUNCTIONS AND ARRAYS
Lecture 04 FUNCTIONS AND ARRAYS 1 Motivations Divide hug tasks to blocks: divide programs up into sets of cooperating functions. Define new functions with function calls and parameter passing. Use functions
More informationChapter 12: Arrays Think Java: How to Think Like a Computer Scientist by Allen B. Downey
Chapter 12: Arrays Think Java: How to Think Like a Computer Scientist 5.1.2 by Allen B. Downey Current Options for Storing Data 1) You need to store the room temperature, such as 62.5, in a variable. What
More informationPointers. Pointer References
Pointers Pointers are variables whose values are the addresses of other variables Basic operations address of (reference) indirection (dereference) Suppose x and y are integers, p is a pointer to an integer:
More informationFrom Java to C. Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides
From Java to C Thanks to Randal E. Bryant and David R. O'Hallaron (Carnegie-Mellon University) for providing the basis for these slides 1 Outline Overview comparison of C and Java Good evening Preprocessor
More informationHigh-performance computing and programming Intro to C on Unix/Linux. Uppsala universitet
High-performance computing and programming Intro to C on Unix/Linux IT Uppsala universitet What is C? An old imperative language that remains rooted close to the hardware C is relatively small and easy
More informationCSC 270 Survey of Programming Languages. C-String Values
CSC 270 Survey of Programming Languages C Lecture 4 Strings C-String Values The most basic way to represent a string of characters in C++ is using an array of characters that ends with a null byte. Example
More informationArrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014.
Arrays Arrays and Pointers l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. EECS 2031 Fall 2014 November 11, 2013 1 2 Arrays: Example
More informationCSC 2400: Computer Systems. Arrays and Strings in C
CSC 2400: Computer Systems Arrays and Strings in C Lecture Overview Arrays! List of elements of the same type Strings! Array of characters ending in \0! Functions for manipulating strings 1 Arrays in C
More informationLanguage comparison. C has pointers. Java has references. C++ has pointers and references
Pointers CSE 2451 Language comparison C has pointers Java has references C++ has pointers and references Pointers Values of variables are stored in memory, at a particular location A location is identified
More informationgcc hello.c a.out Hello, world gcc -o hello hello.c hello Hello, world
alun@debian:~$ gcc hello.c alun@debian:~$ a.out Hello, world alun@debian:~$ gcc -o hello hello.c alun@debian:~$ hello Hello, world alun@debian:~$ 1 A Quick guide to C for Networks and Operating Systems
More informationObjectives. Order (sort) the elements of an array Search an array for a particular item Define, use multidimensional array
Arrays Chapter 7 Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array as an instance variable Use an array not filled
More informationOutline. Lecture 1 C primer What we will cover. If-statements and blocks in Python and C. Operators in Python and C
Lecture 1 C primer What we will cover A crash course in the basics of C You should read the K&R C book for lots more details Various details will be exemplified later in the course Outline Overview comparison
More informationPRINCIPLES OF OPERATING SYSTEMS
PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)
More informationC PROGRAMMING QUESTIONS AND
8/26/2011 C C PROGRAMMING QUESTIONS AND ANSWER http://cquestionbank.blogspot.com Ritesh kumar (1) What will be output if you will compile and execute the following c code? struct marks{ int p:3; int c:3;
More informationRicardo Rocha. Department of Computer Science Faculty of Sciences University of Porto
Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Adapted from the slides Revisões sobre Programação em C, Sérgio Crisóstomo Compilation #include int main()
More informationProgramming in C. Pointers and Arrays
Programming in C Pointers and Arrays NEXT SET OF SLIDES FROM DENNIS FREY S FALL 2011 CMSC313 http://www.csee.umbc.edu/courses/undergraduate/313/fall11/" Pointers and Arrays In C, there is a strong relationship
More informationOutline. Computer programming. Debugging. What is it. Debugging. Hints. Debugging
Outline Computer programming Debugging Hints Gathering evidence Common C errors "Education is a progressive discovery of our own ignorance." Will Durant T.U. Cluj-Napoca - Computer Programming - lecture
More informationF28HS2 Hardware-Software Interface. Lecture 1: Programming in C 1
F28HS2 Hardware-Software Interface Lecture 1: Programming in C 1 Introduction in this half of the course we will study: system level programming in C assembly language programming for the ARM processor
More informationPointers. Part VI. 1) Introduction. 2) Declaring Pointer Variables. 3) Using Pointers. 4) Pointer Arithmetic. 5) Pointers and Arrays
EE105: Software Engineering II Part 6 Pointers page 1 of 19 Part VI Pointers 1) Introduction 2) Declaring Pointer Variables 3) Using Pointers 4) Pointer Arithmetic 5) Pointers and Arrays 6) Pointers and
More informationEM108 Software Development for Engineers
EE108 Section 6 Pointers page 1 of 20 EM108 Software Development for Engineers Section 6 - Pointers 1) Introduction 2) Declaring Pointer Variables 3) Using Pointers 4) Pointer Arithmetic 5) Pointers and
More informationUNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING
UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Final Examination December 16, 2013 2:00 p.m. 4:30 p.m. (150 minutes) Examiners: J. Anderson, B. Korst, J.
More informationIntroduction to C++ 2. A Simple C++ Program. A C++ program consists of: a set of data & function definitions, and the main function (or driver)
Introduction to C++ 1. General C++ is an Object oriented extension of C which was derived from B (BCPL) Developed by Bjarne Stroustrup (AT&T Bell Labs) in early 1980 s 2. A Simple C++ Program A C++ program
More informationProgramming in C. What is C?... What is C?
C Programming in C UVic SEng 265 Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier, in 1969, Ritchie and Thompson developed the Unix operating system We will be focusing on a version
More informationProgramming in C UVic SEng 265
Programming in C UVic SEng 265 Daniel M. German Department of Computer Science University of Victoria 1 SEng 265 dmgerman@uvic.ca C Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier,
More informationSearching Elements in an Array: Linear and Binary Search. Spring Semester 2007 Programming and Data Structure 1
Searching Elements in an Array: Linear and Binary Search Spring Semester 2007 Programming and Data Structure 1 Searching Check if a given element (called key) occurs in the array. Example: array of student
More informationB.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University
Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are
More informationCS 241 Data Organization Pointers and Arrays
CS 241 Data Organization Pointers and Arrays Brooke Chenoweth University of New Mexico Fall 2017 Read Kernighan & Richie 6 Structures Pointers A pointer is a variable that contains the address of another
More informationC Review. MaxMSP Developers Workshop Summer 2009 CNMAT
C Review MaxMSP Developers Workshop Summer 2009 CNMAT C Syntax Program control (loops, branches): Function calls Math: +, -, *, /, ++, -- Variables, types, structures, assignment Pointers and memory (***
More informationargv1.c 1 // Printing command-line arguments 5 6 int main(int argc, string argv[]) 7 { 8 for (int i = 0; i < argc; i++) 9 { 10 printf("%s\n", argv[i])
argv0.c 1 // Printing a command-line argument 5 6 int main(int argc, string argv[]) 7 { 8 if (argc == ) 9 { 10 printf("hello, %s\n", argv[1]); 11 } 1 else 13 { 14 printf("hello, world\n"); 15 } 16 } argv1.c
More informationAP CS Unit 3: Control Structures Notes
AP CS Unit 3: Control Structures Notes The if and if-else Statements. These statements are called control statements because they control whether a particular block of code is executed or not. Some texts
More informationProgramming in C. What is C?... What is C?
Programming in C UVic SEng 265 C Developed by Brian Kernighan and Dennis Ritchie of Bell Labs Earlier, in 1969, Ritchie and Thompson developed the Unix operating system We will be focusing on a version
More informationntroduction to C CS 2022: ntroduction to C nstructor: Hussam Abu-Libdeh (based on slides by Saikat Guha) Fall 2011, Lecture 1 ntroduction to C CS 2022, Fall 2011, Lecture 1 History of C Writing code in
More informationWorksheet 4 Basic Input functions and Mathematical Operators
Name: Student ID: Date: Worksheet 4 Basic Input functions and Mathematical Operators Objectives After completing this worksheet, you should be able to Use an input function in C Declare variables with
More informationIn the case of the dynamic array, the space must be deallocated when the program is finished with it. free(x);
C Notes Relation Between Pointers and Arrays Space for static arrays in C is allocated on the stack when the function that defines them is called and is automatically deleted when the function ends, just
More informationC Language, Token, Keywords, Constant, variable
C Language, Token, Keywords, Constant, variable A language written by Brian Kernighan and Dennis Ritchie. This was to be the language that UNIX was written in to become the first "portable" language. C
More informationMemory Corruption 101 From Primitives to Exploit
Memory Corruption 101 From Primitives to Exploit Created by Nick Walker @ MWR Infosecurity / @tel0seh What is it? A result of Undefined Behaviour Undefined Behaviour A result of executing computer code
More informationCompiling and Running a C Program in Unix
CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 95 ] Compiling and Running a C Program in Unix Simple scenario in which your program is in a single file: Suppose you want to name
More informationSample Problems for Quiz # 2
EE 1301 UMN Introduction to Computing Systems Fall 2013 Sample Problems for Quiz # 2 (with solutions) Here are sample problems to help you prepare for Quiz 2 on Oct. 31. 1. Bit-Level Arithmetic (a) Consider
More informationmith College Computer Science CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut
mith College CSC352 Week #7 Spring 2017 Introduction to C Dominique Thiébaut dthiebaut@smith.edu Learning C in 2 Hours D. Thiebaut Dennis Ritchie 1969 to 1973 AT&T Bell Labs Close to Assembly Unix Standard
More informationESC101N: Fundamentals of Computing End-sem st semester
ESC101N: Fundamentals of Computing End-sem 2010-11 1st semester Instructor: Arnab Bhattacharya 8:00-11:00am, 15th November, 2010 Instructions 1. Please write your name, roll number and section below. 2.
More informationWeek 4, continued. This is CS50. Harvard University. Fall Cheng Gong
This is CS50. Harvard University. Fall 2014. Cheng Gong Table of Contents Files, Headers, and Hex... 1 Structs... 3 Quick Reminder... 7 GDB... 7 Strings... 12 Memory Allocation... 19 Files, Headers, and
More informationcs50.c /**************************************************************************** * CS50 Library 6 *
cs50.c 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. / CS50 Library
More informationMemory. What is memory? How is memory organized? Storage for variables, data, code etc. Text (Code) Data (Constants) BSS (Global and static variables)
Memory Allocation Memory What is memory? Storage for variables, data, code etc. How is memory organized? Text (Code) Data (Constants) BSS (Global and static variables) Text Data BSS Heap Stack (Local variables)
More informationCS61, Fall 2012 Section 2 Notes
CS61, Fall 2012 Section 2 Notes (Week of 9/24-9/28) 0. Get source code for section [optional] 1: Variable Duration 2: Memory Errors Common Errors with memory and pointers Valgrind + GDB Common Memory Errors
More informationComputer Science 50: Introduction to Computer Science I Harvard College Fall Quiz 0 Solutions. Answers other than the below may be possible.
Quiz 0 Solutions Answers other than the below may be possible. Short Answers. 0. :-) 1. 10111111 + 00000001 11000000 2. For efficiency, characters printed to stdout are buffered until a newline is printed
More informationCpSc 1111 Lab 9 2-D Arrays
CpSc 1111 Lab 9 2-D Arrays Overview This week, you will gain some experience with 2-dimensional arrays, using loops to do the following: initialize a 2-D array with data from an input file print out the
More informationCSE 333 Lecture 7 - final C details
CSE 333 Lecture 7 - final C details Steve Gribble Department of Computer Science & Engineering University of Washington Today s topics: - a few final C details header guards and other preprocessor tricks
More information