CS-220 Spring 2018 Test 1 Version A Feb. 28, Name:
|
|
- Daniel Douglas
- 5 years ago
- Views:
Transcription
1 CS-220 Spring 2018 Test 1 Version A Feb. 28, 2018 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : Every function definition in C must specify either void return, a single return type, or a comma separated list of return types. Either void or a single return type is OK, but a list of return types is not allowed. (b) T F : When you invoke a C function, the values of the argument expressions are copied to the parameters of the function. (c) T F : Variables declared in a function can be accessed after the function ends. Automatic variables are deleted when a function ends. Static local variables remain, but are not in scope outside the function. (d) T F : There may be several return statements in a function, but only one return statement will be executed in a single invocation of that function. (e) T F : Upside down code can be avoided by putting function declarations at the top of a C file. However doing so requires specification of the return type, function name, and argument list twice. (f) T F : The main function should return a true value (e.g. 1) if it ends successfully, and a false value (0) if there is a problem. The operating system interprets any non-zero return value from main as an error, and a zero return value as successful program completion. (g) T F : The same bits in memory are always interpreted to be the same value, no matter what type is associated with those bits. (h) T F : An if/else statement is an example of sequential control flow in the C language. An if/else statement is an example of control flow other than the default sequential control flow. (i) T F : In an assignment statement, C will convert the value of the expression on the right hand side of the equals sign to the type of the left hand side, even if this causes the value of the expression to change. (j) T F : The scope of a variable defines when bytes in memory are reserved for that variable, and when the memory for that variable is returned to the operating systsem. The scope defines where a variable can be updated. A local variable has local scope, even if it is static and lasts the lifetime of the program. For the following questions, check the best answer. 2. (5 points) What does the following snippet of code print to stdout? int x []={3, 1, 1, 4, 2 ; char y []={ cat, dog, turkey, ant, owl ; p r i n t f ( %s \n, y [ x [ x [ 4 ] ] ] ) ; cat dog turkey ant owl y[x[x[4]]]==y[x[2]]==y[1] which contains the address of the literal string dog. Page 1 of 8
2 3. (10 points) In the following snippet of code, what does the function f do? struct node { struct node next ; int val ; ; int f ( struct node n ) { i f ( n==null) return 0 ; return 1+f (n >next ) ; Does not do anything meaningful. Counts the number of elements in the list starting at node n. Sums the values of the list starting at node n. Constructs a list whose first node is n. Checks if the list starting with node n is empty. struct node is a structure for a singly linked list. f is a recursive function which counts the number of nodes in the linked list, which is terminated by a NULL next link. As long as the the next pointer is not NULL, the length of the list is one greater than the length of the sub-list that starts with the next pointer. 4. (5 points) What is does the following code snippet print? int x=2; int y=4; i f ( x==1) i f ( y==2) x=6; else y=9; p r i n t f ( x=%d y=%d\n, x, y ) ; x=2 y=4 x=6 y=9 x=6 y=4 x=2 y=9 Compiler error. An ambiguous else statement is associated with the closest if statement even though the indentation suggests otherwise. Page 2 of 8
3 5. (10 points) What does the following code snippet print? char buf=c a l l o c ( 1 0 0, 1 ) ; s t r c p y ( buf, Good s t u f f here! ) ; f r e e ( buf ) ; p r i n t f ( Buf c o n t a i n s : %s \n, buf ) ; Buf contains: Buf contains: 0 May print Buf contains: Good stuff here!, but may print Buff contains: followed by garbage Buf contains: Good Stuff here! Compiler error. After memory is freed, other programs may modify that memory. If no other program has used the memory, it will print corretly, but if other programs have modified the memory, garbage will get printed. Note... there was a typo in the correct answer... should have read Buf, not Buff. Answer the following questions by filling in the blanks. 6. (10 points) Given the following snippet of code, what will get printed to stdout? int x [ 6 ] ; x[6]=1+(x[5]=1+(x[4]=1+(x [ 3 ] = 1 ) ) ) ; x[2]=1+(x[1]=1+(x [ 0 ] = 0 ) ) ; p r i n t f ( x[4]=%d\n, x [ 4 ] ) ; x[4]=2 This problem demonstrates assignment expressions. x[3]=1, x[4]=1+1=2, x[5]=1+2=3, x[6]=3+1=4, x[0]=0, x[1]=1+0=1, x[2]=1+1=2. There is a typo in this problem... I should have declared int x[7] in order to assign x[6], but if the four bytes of memory after the x array are in memory that you can read and write (which is a very high probability), then no error will occur, even though you write pass array bounds. If not, you will get a segmentation violation on the last assignment. 7. (10 points) Given the following snippet of code, what will get printed to stdout? char buf []= I deserve a D but w i l l get a C ; buf [12]=0 x00 ; s t r c a t ( buf, B ) ; buf [13]= ; p r i n t f ( %s \n, buf ) ; I deserve a B but will get a C The first line inserts a null terminator at index 12, which is the location of the letter D. The strcat function replaces the null terminator with a B, but adds a null terminator after the B, overwritting the space before the b in but. The next line then overwrites that null terminator, and restores the blank after B. The original null terminator after the C character at has never been touched, so when the code is done, the string becomes I deserve a B but will get a C. Page 3 of 8
4 8. (10 points) Given the following snippet of code, what will get printed to stdout? int mat [ 2 ] [ 3 ] = { 1 0, 1 1, 2 0, 2 1, 3 0, 3 1 ; int i, j ; for ( i =0; i <2; i ++) { for ( j =0; j <3; j++) { p r i n t f ( %d, mat [ i ] [ j ] ) ; p r i n t f ( \n ) ; The initializer is in row major order, and the matrix mat has 3 columns and 2 rows, so the first row gets the first three values, 10, 11, and 20; and the second row gets the next three values, 21, 30, and 31. The print statement prints each column of row i, followed by a newline, so each output line contains an entire row of output. Note that the compiler will issue a warning message about the fact that the initializer does not have curly braces around the rows, but the program will still work as expected. Page 4 of 8
5 9. In lab yesterday, you studied a program called findmat.c. The code from that program is included on the last page for reference: (a) (5 points) It took some extra effort to create a binary tree from the elements of the input matrix. After the tree is built, does that effort make finding the closest element in the array faster than just walking through the array sequentially? Why? It is faster because, on average, we only look at log 2 (6) entries rather than 6 entries. (b) (5 points) In the findmat program, we only look up one value using the binary tree, so the time to make the binary tree is probably much more than the time we can save using the tree. Describe a situation where it would be worthwhile to spend the extra time to make a binary tree. If we had to look up many different values in the matrix, then the time to make the tree would be distributed over all the lookups. Also, the bigger the matrix, the bigger the benefit of the binary tree, but it also costs more to make a binary tree. The real benefit of the tree is mostly related to the number of times the tree is used. 10. (20 points) Write a new function called maketree to be added to the findmat program. Your new function should take three parameters. The first is a pointer to an int that represents the beginning of a two-dimensional integer matrix (assumed to be in row major order). The second parameter is an int number of rows, and the third parameter is an int number of columns in that matrix. The maketree function should return a struct tnode pointer that contains the root of a binary tree created from that array. Your new function may invoke any of the functions already defined in findmat. Once maketree is coded, we should be able to replace lines 24 through 31 of the findmat program with the following line of code: struct tnode root=maketree((int )mat,3,5); Solution: struct tnode maketree ( int array, int rows, int c o l s ) { struct tnode root=newnode ( array, 0, 0 ) ; int r ; int c ; for ( r =0; r<rows ; r++) { for ( c =0;c<c o l s ; c++) { i n s e r t T r e e ( root, ( array+r c o l s+c ), r, c ) ; return root ; Or... struct tnode maketree ( int array, int rows, int c o l s ) { struct tnode root=newnode ( array, 0, 0 ) ; int r ; int c ; for ( r =0; r<rows ; r++) { for ( c =0;c<c o l s ; c++) { i n s e r t T r e e ( root, array, r, c ) ; array++; return root ; Page 5 of 8
6 Note: In this solution, I depend on the fact that inserttree throws away duplicates, so that when I inserttree for row=0, col=0, it gets discarded; but the original program used this same feature. Page 6 of 8
7 Tear-off Page 1 #include <s t d i o. h> 2 #include <s t d l i b. h> 3 #define abs ( a ) ( a>=0? a : (a ) ) 4 5 struct tnode { 6 int val ; 7 int row ; int c o l ; 8 struct tnode l e f t ; struct tnode r i g h t ; 9 ; struct tnode newnode ( int val, int row, int c o l ) ; 12 void i n s e r t T r e e ( struct tnode root, int val, int row, int c o l ) ; 13 void printsortedtree ( struct tnode root ) ; 14 void findtree ( struct tnode root, int val, struct tnode c l o s e s t ) ; 15 void f r e e T r e e ( struct tnode root ) ; int main ( int argc, char argv ) { 18 int mat [ 3 ] [ 5 ] = { { 3 1, 4 5, 1 2, 1 6, 4 4, { 9 8, 7 5, 1 3, 4 2, 1 1, { 6, 1 4, 5 0, 1 0, 8 1 ; i f ( argc!=2) { 21 p r i n t f ( Invoke as %s <value >\n, argv [ 0 ] ) ; 22 return 0 ; struct tnode root=newnode (mat [ 0 ] [ 0 ], 0, 0 ) ; 25 int row ; 26 for ( row=0;row <3;row++) { 27 int c o l ; 28 for ( c o l =0; col <5; c o l++) { 29 i n s e r t T r e e ( root, mat [ row ] [ c o l ], row, c o l ) ; printsortedtree ( root ) ; 33 int l o s t=a t o i ( argv [ 1 ] ) ; 34 findtree ( root, l o s t,null) ; 35 f r e e T r e e ( root ) ; 36 return 0 ; struct tnode newnode ( int val, int row, int c o l ) { 40 struct tnode new = ( struct tnode ) malloc ( sizeof ( struct tnode ) ) ; 41 new >val=val ; 42 new >row=row ; new >c o l=c o l ; 43 new >l e f t=null; new >r i g h t=null; 44 return new ; void i n s e r t T r e e ( struct tnode root, int val, int row, int c o l ) { 48 i f ( val==root >val ) return ; // Don t i n s e r t a v a l u e t h a t s a l r e a d y t h e r e 49 i f ( val < root >val ) { 50 i f ( root >l e f t==null) root >l e f t=newnode ( val, row, c o l ) ; 51 else i n s e r t T r e e ( root >l e f t, val, row, c o l ) ; 52 else { // must be val >root >v a l Page 7 of 8
8 53 i f ( root >r i g h t==null) root >r i g h t=newnode ( val, row, c o l ) ; 54 else i n s e r t T r e e ( root >r i g h t, val, row, c o l ) ; void printsortedtree ( struct tnode root ) { 59 i f ( root >l e f t ) p rintsortedtree ( root >l e f t ) ; 60 p r i n t f ( mat[%d ][% d ] = %3d\n, root >row, root >col, root >val ) ; 61 i f ( root >r i g h t ) printsortedtree ( root >r i g h t ) ; void findtree ( struct tnode root, int val, struct tnode c l o s e s t ) { 65 i f ( c l o s e s t==null) c l o s e s t=root ; 66 i f ( val==root >val ) { 67 p r i n t f ( Value %d i s in mat[%d][%d ] \ n, val, root >row, root >c o l ) ; 68 return ; i f ( abs ( val root >val)<abs ( val c l o s e s t >val ) ) { 71 c l o s e s t=root ; i f ( val<root >val ) { 74 i f ( root >l e f t==null) { 75 p r i n t f ( C l o s e s t value to %d i s in mat[%d][%d]=%d\n, 76 val, c l o s e s t >row, c l o s e s t >col, c l o s e s t >val ) ; 77 return ; findtree ( root >l e f t, val, c l o s e s t ) ; 80 else { 81 i f ( root >r i g h t==null) { 82 p r i n t f ( C l o s e s t value to %d i s in mat[%d][%d]=%d\n, 83 val, c l o s e s t >row, c l o s e s t >col, c l o s e s t >val ) ; 84 return ; findtree ( root >r i g h t, val, c l o s e s t ) ; void f r e e T r e e ( struct tnode root ) { 91 i f ( root >l e f t ) f r e e T r e e ( root >l e f t ) ; 92 i f ( root >r i g h t ) f r e e T r e e ( root >r i g h t ) ; 93 f r e e ( root ) ; 94 Question: Total Points: Bonus Points: Page 8 of 8
CS-211 Fall 2017 Test 1 Version A Oct. 2, Name:
CS-211 Fall 2017 Test 1 Version A Oct. 2, 2017 True/False Questions... Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : If I code a C
More informationCSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community
CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine
More informationCS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University
9/5/6 CS Introduction to Computing II Wayne Snyder Department Boston University Today: Arrays (D and D) Methods Program structure Fields vs local variables Next time: Program structure continued: Classes
More informationECE264 Spring 2013 Final Exam, April 30, 2013
ECE264 Spring 2013 Final Exam, April 30, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
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 informationCS-211 Fall 2017 Test 1 Version Practice For Test on Oct. 2, Name:
CS-211 Fall 2017 Test 1 Version Practice For Test on Oct. 2, 2017 True/False Questions... Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a)
More informationReview of the C Programming Language for Principles of Operating Systems
Review of the C Programming Language for Principles of Operating Systems Prof. James L. Frankel Harvard University Version of 7:26 PM 4-Sep-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights
More informationVariables Data types Variable I/O. C introduction. Variables. Variables 1 / 14
C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition
More informationDynamic memory allocation
Dynamic memory allocation outline Memory allocation functions Array allocation Matrix allocation Examples Memory allocation functions (#include ) malloc() Allocates a specified number of bytes
More informationKurt Schmidt. October 30, 2018
to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed
More informationECE264 Fall 2013 Exam 3, November 20, 2013
ECE264 Fall 2013 Exam 3, November 20, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.
More informationReview of the C Programming Language
Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the
More informationCSCI 2132 Final Exam Solutions
Faculty of Computer Science 1 CSCI 2132 Final Exam Solutions Term: Fall 2018 (Sep4-Dec4) 1. (12 points) True-false questions. 2 points each. No justification necessary, but it may be helpful if the question
More informationCS-211 Fall 2017 Test 2 Version A November 29, Name:
CS-211 Fall 2017 Test 2 Version A November 29, 2017 True/False Questions... Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : The control
More informationCS 237 Meeting 19 10/24/12
CS 237 Meeting 19 10/24/12 Announcements 1. Midterm: New date: Oct 29th. In class open book/notes. 2. Try to complete the linear feedback shift register lab in one sitting (and please put all the equipment
More informationCS-220 Spring 2018 Final Exam Version Practice May 10, Name:
CS-220 Spring 2018 Final Exam Version Practice May 10, 2018 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : One of the advantages of
More informationCS 241 Data Organization Binary Trees
CS 241 Data Organization Binary Trees Brooke Chenoweth University of New Mexico Fall 2017 Binary Tree: Kernighan and Ritchie 6.5 Read a file and count the occurrences of each word. now is the time for
More informationBinghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program
Syntax What the Compiler needs to understand your program 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line Possibly replacing it with other
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 informationC-String Library Functions
Strings Class 34 C-String Library Functions there are several useful functions in the cstring library strlen: the number of characters before the \0 strncat: concatenate two strings together strncpy: overwrite
More informationCA341 - Comparative Programming Languages
CA341 - Comparative Programming Languages David Sinclair Dynamic Data Structures Generally we do not know how much data a program will have to process. There are 2 ways to handle this: Create a fixed data
More informationCS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010
CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011 Lectures 1-22 Moaaz Siddiq Asad Ali Latest Mcqs MIDTERM EXAMINATION Spring 2010 Question No: 1 ( Marks: 1 ) - Please
More informationCS 223: Data Structures and Programming Techniques. Exam 2
CS 223: Data Structures and Programming Techniques. Exam 2 Instructor: Jim Aspnes Work alone. Do not use any notes or books. You have approximately 75 minutes to complete this exam. Please write your answers
More informationLab Exam 1 D [1 mark] Give an example of a sample input which would make the function
CMPT 127 Spring 2019 Grade: / 20 First name: Last name: Student Number: Lab Exam 1 D400 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return -1? Answer:
More informationCS2141 Software Development using C/C++ C++ Basics
CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short
More informationFall 2018 Discussion 2: September 3, 2018
CS 61C C Basics Fall 2018 Discussion 2: September 3, 2018 1 C C is syntactically similar to Java, but there are a few key differences: 1. C is function-oriented, not object-oriented; there are no objects.
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 informationJava Bytecode (binary file)
Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.
More informationAPT Session 4: C. Software Development Team Laurence Tratt. 1 / 14
APT Session 4: C Laurence Tratt Software Development Team 2017-11-10 1 / 14 http://soft-dev.org/ What to expect from this session 1 C. 2 / 14 http://soft-dev.org/ Prerequisites 1 Install either GCC or
More informationA brief introduction to C programming for Java programmers
A brief introduction to C programming for Java programmers Sven Gestegård Robertz September 2017 There are many similarities between Java and C. The syntax in Java is basically
More informationBinary Search Tree 1.0. Generated by Doxygen Mon Jun :12:39
Binary Search Tree 1.0 Generated by Doxygen 1.7.1 Mon Jun 6 2011 16:12:39 Contents 1 Binary Search Tree Program 1 1.1 Introduction.......................................... 1 2 Data Structure Index 3
More informationLab Instructor : Jean Lai
Lab Instructor : Jean Lai Group related statements to perform a specific task. Structure the program (No duplicate codes!) Must be declared before used. Can be invoked (called) as any number of times.
More informationFORM 2 (Please put your name and form # on the scantron!!!!)
CS 161 Exam 2: FORM 2 (Please put your name and form # on the scantron!!!!) True (A)/False(B) (2 pts each): 1. Recursive algorithms tend to be less efficient than iterative algorithms. 2. A recursive function
More informationArray. Prepared By - Rifat Shahriyar
Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types
More informationLab Exam 1 D [1 mark] Give an example of a sample input which would make the function
Grade: / 20 Lab Exam 1 D500 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return 0? Answer: Anything that is not a floating point number such as 4.567 or
More informationECE264 Spring 2014 Exam 2, March 11, 2014
ECE264 Spring 2014 Exam 2, March 11, 2014 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.
More informationTwister: Language Reference Manual
Twister: Language Reference Manual Manager: Anand Sundaram (as5209) Language Guru: Arushi Gupta (ag3309) System Architect: Annalise Mariottini (aim2120) Tester: Chuan Tian (ct2698) February 23, 2017 Contents
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 informationIECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.
Subject code - CCP01 Chapt Chapter 1 INTRODUCTION TO C 1. A group of software developed for certain purpose are referred as ---- a. Program b. Variable c. Software d. Data 2. Software is classified into
More informationData Structure Series
Data Structure Series This series is actually something I started back when I was part of the Sweet.Oblivion staff, but then some things happened and I was no longer able to complete it. So now, after
More informationCHAPTER 7 OBJECTS AND CLASSES
CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and
More informationCS 0449 Sample Midterm
Name: CS 0449 Sample Midterm Multiple Choice 1.) Given char *a = Hello ; char *b = World;, which of the following would result in an error? A) strlen(a) B) strcpy(a, b) C) strcmp(a, b) D) strstr(a, b)
More informationCS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015
CS 141 - Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015 You may take this test with you after the test, but you must turn in your answer sheet. This test has the following sections:
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More information15-213/18-243, Spring 2011 Exam 2
Andrew login ID: Full Name: Section: 15-213/18-243, Spring 2011 Exam 2 Thursday, April 21, 2011 v2 Instructions: Make sure that your exam is not missing any sheets, then write your Andrew login ID, full
More informationMore loops Ch
More loops Ch 3.3-3.4 Announcements Quiz next week! -Covers up to (and including) HW1 (week 1-3) -Topics: cout/cin, types, scope, if/else, etc. Review: Loops We put a loop around code that we want to run
More informationProcessor. Lecture #2 Number Rep & Intro to C classic components of all computers Control Datapath Memory Input Output
CS61C L2 Number Representation & Introduction to C (1) insteecsberkeleyedu/~cs61c CS61C : Machine Structures Lecture #2 Number Rep & Intro to C Scott Beamer Instructor 2007-06-26 Review Continued rapid
More informationCS349/SE382 A1 C Programming Tutorial
CS349/SE382 A1 C Programming Tutorial Erin Lester January 2005 Outline Comments Variable Declarations Objects Dynamic Memory Boolean Type structs, enums and unions Other Differences The Event Loop Comments
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler
More informationCoding Standards for C
Why have coding standards? Coding Standards for C Version 6.1 CS480s11 It is a known fact that 80% of the lifetime cost of a piece of software goes to maintenance. Therefore it makes sense for all programs
More informationData Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA === Homework submission instructions ===
Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA email: dsa1@csientuedutw === Homework submission instructions === For Problem 1, submit your source code, a Makefile to compile
More informationTutorial 1: Introduction to C Computer Architecture and Systems Programming ( )
Systems Group Department of Computer Science ETH Zürich Tutorial 1: Introduction to C Computer Architecture and Systems Programming (252-0061-00) Herbstsemester 2012 Goal Quick introduction to C Enough
More informationBOOLEAN EXPRESSIONS CONTROL FLOW (IF-ELSE) INPUT/OUTPUT. Problem Solving with Computers-I
BOOLEAN EXPRESSIONS CONTROL FLOW (IF-ELSE) INPUT/OUTPUT Problem Solving with Computers-I Announcements HW02: Complete (individually)using dark pencil or pen, turn in during lab section next Wednesday Please
More informationMIDTERM TEST EESC 2031 Software Tools June 13, Last Name: First Name: Student ID: EECS user name: TIME LIMIT: 110 minutes
MIDTERM TEST EESC 2031 Software Tools June 13, 2017 Last Name: First Name: Student ID: EECS user name: TIME LIMIT: 110 minutes This is a closed-book test. No books and notes are allowed. Extra space for
More informationCoding Standards for C
Why have coding standards? Coding Standards for C Version 6.3 It is a known fact that 80% of the lifetime cost of a piece of software goes to maintenance. Therefore it makes sense for all programs within
More informationAnswer all questions. Write your answers only in the space provided. Full marks = 50
Answer all questions. Write your answers only in the space provided. Full marks = 50 1. Answer the following: [2+3+2+1=8 marks] a) What are the minimum and maximum numbers that can be represented in 10-bit
More informationAnne Bracy CS 3410 Computer Science Cornell University
Anne Bracy CS 3410 Computer Science Cornell University The slides are the product of many rounds of teaching CS 3410 by Professors Weatherspoon, Bala, Bracy, McKee, and Sirer. See P&H 2.8 and 2.12, and
More informationProcedures, Parameters, Values and Variables. Steven R. Bagley
Procedures, Parameters, Values and Variables Steven R. Bagley Recap A Program is a sequence of statements (instructions) Statements executed one-by-one in order Unless it is changed by the programmer e.g.
More informationDeclaring Pointers. Declaration of pointers <type> *variable <type> *variable = initial-value Examples:
1 Programming in C Pointer Variable A variable that stores a memory address Allows C programs to simulate call-by-reference Allows a programmer to create and manipulate dynamic data structures Must be
More informationHeap Arrays and Linked Lists. Steven R. Bagley
Heap Arrays and Linked Lists Steven R. Bagley Recap Data is stored in variables Can be accessed by the variable name Or in an array, accessed by name and index Variables and arrays have a type Create our
More informationLab 4: Tracery Recursion in C with Linked Lists
Lab 4: Tracery Recursion in C with Linked Lists For this lab we will be building on our previous lab at the end of the previous lab you should have had: #include #include char * make_string_from
More informationIMPORTANT QUESTIONS IN C FOR THE INTERVIEW
IMPORTANT QUESTIONS IN C FOR THE INTERVIEW 1. What is a header file? Header file is a simple text file which contains prototypes of all in-built functions, predefined variables and symbolic constants.
More informationQuiz Start Time: 09:34 PM Time Left 82 sec(s)
Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability
More informationBinghamton University. CS-120 Summer Introduction to C. Text: Introduction to Computer Systems : Chapters 11, 12, 14, 13
Introduction to C Text: Introduction to Computer Systems : Chapters 11, 12, 14, 13 Problem: Too Many Details For example: Lab 7 Bubble Sort Needed to keep track of too many details! Outer Loop When do
More informationMultiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)
Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program
More informationQUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:
QUIZ 1. Explain the meaning of the angle brackets in the declaration of v below: This is a template, used for generic programming! QUIZ 2. Why is the vector class called a container? 3. Explain how the
More informationCOP Programming Concepts Spring 1999 CLOSED BOOK Exam #1 100 Points NAME
CLOSED BOOK Exam #1 100 Points NAME 1. The following program has (at least) 10 syntax errors. Circle each error. Write the corrected program in the blank space below. 2 points for each error you find.
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 informationEE 312 Fall 2017 Midterm 1 October 12, 2017
EE 312 Fall 2017 Midterm 1 October 12, 2017 Name: EID: Recitation time: Recitation TA (circle one): Colin Huy Give clear, legible answers. If you give more than one answer, we will randomly choose one
More informationMIDTERM EXAM. CS 217 October 28, Name: Precept: Honor Code: Score: Problem Score Max
MIDTERM EXAM CS 217 October 28, 1999 Name: Precept: Honor Code: Score: Problem Score Max 1 15 2 5 3 10 4 15 5 5 6 10 7 10 Total 70 1 1. Number Systems (a) Translate the following decimal numbers to binary,
More information1 Dynamic Memory continued: Memory Leaks
CS104: Data Structures and Object-Oriented Design (Fall 2013) September 3, 2013: Dynamic Memory, continued; A Refresher on Recursion Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we continue
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationWeek 3 Lecture 2. Types Constants and Variables
Lecture 2 Types Constants and Variables Types Computers store bits: strings of 0s and 1s Types define how bits are interpreted They can be integers (whole numbers): 1, 2, 3 They can be characters 'a',
More informationCHAPTER 4 FUNCTIONS. 4.1 Introduction
CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main
More informationadvanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef
today advanced data types (1) typedef. mon 23 sep 2002 homework #1 due today homework #2 out today quiz #1 next class 30-45 minutes long one page of notes topics: C advanced data types dynamic memory allocation
More informationIntroduction to C Language (M3-R )
Introduction to C Language (M3-R4-01-18) 1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter in OMR answer sheet supplied with the question paper, following
More informationCS 31: Intro to Systems Arrays, Structs, Strings, and Pointers. Kevin Webb Swarthmore College March 1, 2016
CS 31: Intro to Systems Arrays, Structs, Strings, and Pointers Kevin Webb Swarthmore College March 1, 2016 Overview Accessing things via an offset Arrays, Structs, Unions How complex structures are stored
More informationLecture 05: Methods. AITI Nigeria Summer 2012 University of Lagos.
Lecture 05: Methods AITI Nigeria Summer 2012 University of Lagos. Agenda What a method is Why we use methods How to declare a method The four parts of a method How to use (invoke) a method The purpose
More informationCS201 Latest Solved MCQs
Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability
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 informationCS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.
CS61C Machine Structures Lecture 3 Introduction to the C Programming Language 1/23/2006 John Wawrzynek (www.cs.berkeley.edu/~johnw) www-inst.eecs.berkeley.edu/~cs61c/ CS 61C L03 Introduction to C (1) Administrivia
More informationADTS, GRAMMARS, PARSING, TREE TRAVERSALS
3//15 1 AD: Abstract Data ype 2 Just like a type: Bunch of values together with operations on them. Used often in discussing data structures Important: he definition says ntthing about the implementation,
More informationLooping and Counting. Lecture 3 Hartmut Kaiser hkaiser/fall_2012/csc1254.html
Looping and Counting Lecture 3 Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2012/csc1254.html Abstract First we ll discuss types and type safety. Then we will modify the program
More informationA Short Summary of Javali
A Short Summary of Javali October 15, 2015 1 Introduction Javali is a simple language based on ideas found in languages like C++ or Java. Its purpose is to serve as the source language for a simple compiler
More informationCHAPTER 7 OBJECTS AND CLASSES
CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and
More informationLooping and Counting. Lecture 3. Hartmut Kaiser hkaiser/fall_2011/csc1254.html
Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/fall_2011/csc1254.html 2 Abstract First we ll discuss types and type safety. Then we will modify the program we developed last time (Framing
More informationDC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use? The heterogeneous linked list contains different data types in its nodes and we need a link
More informationIntroduction to C# Applications
1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making
More informationA6-R3: DATA STRUCTURE THROUGH C LANGUAGE
A6-R3: DATA STRUCTURE THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be answered in the TEAR-OFF
More informationCS 376b Computer Vision
CS 376b Computer Vision 09 / 25 / 2014 Instructor: Michael Eckmann Today s Topics Questions? / Comments? Enhancing images / masks Cross correlation Convolution C++ Cross-correlation Cross-correlation involves
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 informationManaging Memory. (and low level Data Structures) Lectures 22, 23. Hartmut Kaiser.
Managing Memory (and low level Data Structures) Lectures 22, 23 Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/ hkaiser/spring_2015/csc1254.html Programming Principle of the Day Avoid Premature
More informationThe Warhol Language Reference Manual
The Warhol Language Reference Manual Martina Atabong maa2247 Charvinia Neblett cdn2118 Samuel Nnodim son2105 Catherine Wes ciw2109 Sarina Xie sx2166 Introduction Warhol is a functional and imperative programming
More informationSection 1: True / False (2 points each, 30 pts total)
Section 1: True / False (2 points each, 30 pts total) Circle the word TRUE or the word FALSE. If neither is circled, both are circled, or it impossible to tell which is circled, your answer will be considered
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 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 informationc) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.
2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C
More informationCS ) PROGRAMMING ASSIGNMENT 11:00 PM 11:00 PM
CS3114 (Fall 2017) PROGRAMMING ASSIGNMENT #4 Due Thursday, December 7 th @ 11:00 PM for 100 points Due Tuesday, December 5 th @ 11:00 PM for 10 point bonus Last updated: 11/13/2017 Assignment: Update:
More information