COP 3223 Introduction to Programming with C - Study Union - Fall 2017

Similar documents
COP 3223 Introduction to Programming with C - Study Union - Fall 2017

COP 3223 Introduction to Programming with C - Study Union - Spring 2018

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

CS 0449 Sample Midterm

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Chapter 5. Section 5.4 The Common String Library Functions. CS 50 Hathairat Rattanasook

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

Strings(2) CS 201 String. String Constants. Characters. Strings(1) Initializing and Declaring String. Debzani Deb

CSE 142 Wi01 Midterm 2 page 1 of 6

Final Intro to C Review

COP 3223 Final Review

Parameter passing. Programming in C. Important. Parameter passing... C implements call-by-value parameter passing. UVic SEng 265

Government Polytechnic Muzaffarpur.

Principles of C and Memory Management

Array Initialization

Fundamental of Programming (C)

Solutions to Assessment

Arrays. Example: Run the below program, it will crash in Windows (TurboC Compiler)

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Decision Making and Loops

Unit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array?

M1-R4: Programing and Problem Solving using C (JAN 2019)

C Programming Language

Arrays and Applications

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

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

Language comparison. C has pointers. Java has references. C++ has pointers and references

ARRAYS(II Unit Part II)

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #07. Topic: Pointer in C Date:

ESC101N: Fundamentals of Computing End-sem st semester

COP 3223 Final Review

Answer all questions. Write your answers only in the space provided. Full marks = 50

CGS 3460 Summer 07 Midterm Exam

The University of Calgary. ENCM 339 Programming Fundamentals Fall 2016

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows

UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 2 Solution. Examiner : Ritu Chaturvedi Dated :November 27th, Student Name: Student Number:

16.216: ECE Application Programming Spring 2015 Exam 2 Solution

Foundation Exam - Sample Problems for New Topics

TEST BDA24202 / BTI10202 COMPUTER PROGRAMMING May 2013

EECE.2160: ECE Application Programming Fall 2017 Exam 3 December 16, 2017

SOFTWARE Ph.D. Qualifying Exam Fall 2017

MTH 307/417/515 Final Exam Solutions

Basic and Practice in Programming Lab7

C programming basics T3-1 -

ECE264 Fall 2013 Exam 1, September 24, 2013

Gabriel Hugh Elkaim Spring CMPE 013/L: C Programming. CMPE 013/L: C Programming

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

Func%ons. CS449 Fall 2017

Procedural Programming & Fundamentals of Programming

Subject: Fundamental of Computer Programming 2068

C Program Development and Debugging under Unix SEEM 3460

Lecture 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?

'C' Programming Language

Operators And Expressions

2. Which of the following will print the value 2 for the above code?

Scheme G. Sample Test Paper-I. Course Name : Computer Engineering Group Course Code : CO/CD/CM/CW/IF Semester : Second Subject Tile : Programming in C

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

Practice problems Set 2

Computer Programming. C Array is a collection of data belongings to the same data type. data_type array_name[array_size];

This is CS50. Harvard University Fall Quiz 0 Answer Key

COMP1917 Computing 1 Written Exam Sample Questions

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Midterm Review. Short Answer. Short Answer. Practice material from the Winter 2014 midterm. Will cover some (but not all) of the questions.

CSE 333 Midterm Exam 7/27/15 Sample Solution

Variables, Pointers, and Arrays

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

AMCAT Procedure functions and scope Sample Questions

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays

2-D Arrays. Of course, to set each grid location to 0, we have to use a loop structure as follows (assume i and j are already defined):

Arrays and Pointers. CSE 2031 Fall November 11, 2013

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

Computers Programming Course 10. Iulian Năstac

Flow of Control. Selection. if statement. True and False in C False is represented by any zero value. switch

Maltepe University Computer Engineering Department. BİL 133 Algoritma ve Programlama. Chapter 8: Arrays and pointers

CS 223: Data Structures and Programming Techniques. Exam 2

Problem 2 Add the two 2 s complement signed 8-bit values given below, and express your answer in decimal.

ECE 264 Exam 2. 6:30-7:30PM, March 9, You must sign here. Otherwise you will receive a 1-point penalty.

Memory Allocation. General Questions

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

type arrayname [ size type arrayname [ size ] = { item ,, item size size

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012

Pointers, Dynamic Data, and Reference Types

Please note that, for all What will be output questions, the answer could be error or indefinite. However, there is no compile error.

Make sure the version number is marked on your scantron sheet. This is Version 1

CS240: Programming in C

Arrays and Pointers. Arrays. Arrays: Example. Arrays: Definition and Access. Arrays Stored in Memory. Initialization. EECS 2031 Fall 2014.

COP Study Union - Fall 2017

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

CS 222: Pointers and Manual Memory Management

Introduction to C. Sami Ilvonen Petri Nikunen. Oct 6 8, CSC IT Center for Science Ltd, Espoo. int **b1, **b2;

OBJECTIVE QUESTIONS: Choose the correct alternative:

Storage class and Scope:

Programming in C++: Assignment Week 1

Chapter 2 (Dynamic variable (i.e. pointer), Static variable)

C Language Part 3. Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Final CSE 131B Spring 2005

Character Strings. String-copy Example

Q1: Multiple choice / 20 Q2: Arrays / 40 Q3: Functions / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

Transcription:

COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional................................. 5 3.2 Two Dimensional................................. 6 3.3 Strings and String Functions.......................... 6 4 File I/O 7 5 Pointers 8 6 Pass by Reference Functions 9 7 Dynamic Memory Allocation 10 8 Structs 12 8.1 Pointers to Structs................................ 12 9 Linked Lists 12 1

1 Code Tracing 1) What is the output of the following segment of code? int a = 5, b = 9; a = b + 15 * 2; b += a - 6 / 3; a += a + b; b++; printf("%d,%d\n", a,b); A) 120,43 B) 120,24 C) 124,47 D) 115,30 2) What is the output of the following segment of code? int x = 12, y = 4, z = 7; if(x > 2 * z) x = 3 * y; y += 5* z; z -= x * y + 4; else if(y * 2 > 6) x += 15 * 2; y = x + z * 2 / 7; z += x % y; else x = y + 12; y = x % z + 4; z = x + y * y % 2; printf("%d %d %d\n", x,y,z); 2

3) What is the output of the following segment of code? int a = 7, b, c; b = a % 6 + 5; c = b * a / (b % a); a /= (c % b); printf("%d, %d, %d\n", b, c, a); 4) What is the output of the following segment of code? (Hint: There may be more output lines than necessary) int i; int j; for(i = 0; i < 3; i++) for(j = i; j < 4; j++) printf("%d", i + j); if(j == 3) printf("\n"); else printf(" "); Output Line 1: Output Line 2: Output Line 3: Output Line 4: Output Line 5: Output Line 6: 3

5) What is the output of the following segment of code? int i = 25, a = 7, b = 13, c = 12; while(i % 10 == 0) a *= i % b * c + c * 2; b -= b % c * a / 4 * (b+a); c = c * a + b - (c * b + 2 * a); a -= b; b += a * 2; c += 5; i--; printf("%d %d %d\n", a, b, c); 6) What is the difference between a while loop, and a do while loop? 2 Pass by Value Functions 1) Write a function prototype for a function named findarea that returns an integer and has two integers named width and height as parameters 2) Given the function prototype above, fill in the function so that it finds the area of a square with dimensions width and height 4

3)What is the output of the following lines of code? int main(void) int x = 12, y = 15, z; // mult(a,b) returns a * b z = mult(y,3); // pow(a,b) returns a^b x = pow(1,2); z += pow(y,1) + x; printf("%d %d %d\n", x, y, z); return 0; 3 Statically Allocated Arrays 3.1 One Dimensional 1) Write a function that receives an integer array and an integer representing the size of the array, and returns the an integer that holds the largest value in that array 5

3.2 Two Dimensional 1) In main, write a program that creates a 4x4 two dimensional array and populates it with random values between 1-100 3.3 Strings and String Functions 1) Draw the boxes representing an array that contains the string hello 2) When using the string copy function, which argument is the destination and which is the source? 3) Does the string length function account for the null terminator? 4) True or False: strcat(str1, str2) returns the string str2str1 5) What does the string compare function return if two strings are lexicographically equivalent? 6

6) Fill in the following function that is given two strings of equal length and compares them. If they are the same, create a 3rd string that is the result of concatenating the second string with the first, and print that string void stringstuff(char str1[], char str2[]) 4 File I/O 1) Write a program that scans in all of the integers from a file named input.txt and outputs their sum. The file is of the following format: the first line contains an integer n, and will be followed by n integers. int main(void) 7

5 Pointers 1) What is wrong with the following lines of code? int x = 15; int *p = &x; *p = 9; printf("%d\n", p); 2) Fill in the blanks with the proper data types that each variable should have. r; c; h; i; a; r = &c; a = r; *r = 17; *h = a; *a = 99; i = &h; 3) How would we set the element at position 3 of an array called array to be equal to 7 using pointer notation? 8

6 Pass by Reference Functions 1) Fill in the following function that is given two pointers as parameters and then swaps their values void swap(int *x, int *y) 2) Use the function from the previous question so that the values of a and b are swapped int a = 5, b = 7; 9

7 Dynamic Memory Allocation 1) Fill in the following main function so that you ask the user to input an integer, and then use that integer to allocate an integer array of that size, and populate it with random values between 1-100 int main(void) 10

2) You are given a file called words.txt that contains an integer n, followed by n lines that contain one string each. Allocate a two dimensional character array that contains exactly n strings, and where each row of the array is allocated memory that is exactly equal to the size of the string int main(void) 11

8 Structs 8.1 Pointers to Structs 9 Linked Lists 12