CMPSC 16 PRACTICE MIDTERM 2 SUMMER All programming questions in this exam should be answered based on the programming language C.

Size: px
Start display at page:

Download "CMPSC 16 PRACTICE MIDTERM 2 SUMMER All programming questions in this exam should be answered based on the programming language C."

Transcription

1 CMPSC 16 PRACTICE MIDTERM 2 SUMMER 2014 All programming questions in this exam should be answered based on the programming language C.

2 Sample Exam Problem. Know the definitions of the following terms and be able to match them with a desciptive phrase (as in exam 1). abtraction, reusability, function invocation, function definition, function prototype, formal parameters, actual prameters, call-by-value, scope, global variable, local variable, recursive function, array, dereference operator, address operator, pointer, dynamic memory, static memory. Sample Exam Problem. Consider an input file input.txt with the following content: CS 16 8/ The first character in the file is C and the last character is.. There is a blank (space) character after "CS". Consider the code segment below. Show the contents of the file output.txt after this code is executed by completing the output shown below: CODE SEGMENT: #include <stdio.h> int main(void) { char c; int value = 0; int i; FILE * input, * output; input = fopen("input.txt", "r"); output = fopen("output.txt", "w"); fscanf(input, "%c", &c); fprintf(output, "c: %c\n\n", c); fscanf(input, "%d", &value); fprintf(output, "value: %d\n\n", value); fscanf(input, "%c", &c); fscanf(input, "%d", &value); fprintf(output, "value: %d\n\n", value); OUTPUT: c: value: value: c: value: for(i = 0; i <= 6; i++) fscanf(input, "%c", &c); fprintf(output, "c: %c\n\n", c); fscanf(input, "%d", &value); fprintf(output, "value: %d\n\n", value);

3 Sample Exam Problem. Show the contents of the array x after all the statements in the following code segment are executed. List the contents of x starting with the first element of the array, and write a question mark? if the contents are not defined. CODE SEGMENT: CONTENTS OF x: int x[5]; x[2] = 1; x[3] = 5; x[x[2]] = x[2] * 2; x[5 - x[1]] = 9; /* What are the contents of x here? */ Sample Exam Problem. Write a C programming statement using malloc that will declare a pointer named xp which points to a dynamically allocate block of memory with space for 10 integer values. Fill in your answer on the blank line. (Hint: see the lab on pointers). int * xp =

4 Sample Exam Problem. Given the following declarations, show the results of evaluating the following expressions. If the expression accesses a section of memory that contains unknown values write?. (Hint: for studying, try it out in ch) int y[6] = { 2,3,5,7,11,13; int *yp = &y[2]; EXPRESSION: *y VALUE: *yp *(yp + y[0]) *yp + y[0] yp[4] + 1

5 Sample Exam Problem. Given the following code segment, show the output that will be generated by this code by completing the partial output shown below. CODE SEGMENT: #include<stdio.h> int value = 0; void func1(int x) { x = 5; void func2(int *x) { *x = 10; void func3(int x) { value = x; int main(void) { int x = 0; func1(x); printf("x is: %d\n\n", x); func2(&x); printf("x is: %d\n\n", x); OUTPUT: x is: x is: value is: value is: x is: value is: value is: func1(value); printf("value is: %d\n\n", value); func2(&value); printf("value is: %d\n\n", value); func3(5); printf("x is: %d\n\n", x); printf("value is: %d\n\n", value); func2(&value); func3(value - 1); printf("value is: %d\n\n", value);

6 Sample Exam Problem Write a code segement to compute the sum of three 3-by-3 matrices. We want to compute D = A + B + C. Fill in the missing portion below. #include<stdio.h> int main(){ int A[3][3] = {{-1,3,6,{19, -8-1,{-8, -6, 1; int B[3][3] = {{12, 0, 0, {5, 2, -1, {6,5,7; int C[3][3] = {{9,8,7, {1,2,3, {5,4,6; int D[3][3]; int i, j, n = 3; // Compute D = A + B + C // Fill in the missing code here // print D printf("\nmatrix D = A + B + C:\n"); for(i = 0; i < n; i++){ for(j = 0; j < n; j++){ printf("%3i ", D[i][j]); printf("\n"); The program should produce the following expected output: Matrix D = A + B + C:

7 Sample Exam Problem. Consider the imaginary memory layout below in which addresses are four digit integers and all values stored in memory are represented as positive integers. Assume that an integer takes up 4 bytes, so that adjacent memory addresses differ by 4. So, incrementing an address by 1 results in an address that is 4 bytes away. For example, &y is 1012, &y + 1 is 1016, &y + 2 is 1020, and so on. The addresses, memory contents, and variable names associated with particular memory blocks are shown in the table. Address Memory Contents Variable x y z Fill in the following table showing the value of the given expressions. EXPRESSION: x VALUE: *1008 &y *&y &x+1 *z+4 **(&x+4) *(&z+1)

8 Sample Exam Problem. Write a function that searches for a value in an array. The function will take three arguments: 1) an integer value that is greater than 0 and indicates the size of the array, 2) an integer array of that size, and 3) an integer value that we would like to search. The function should return an integer value. It should return -1 if the value that is being searched is not in the array. Otherwise, it should return the position of the value in the array (return 0 for the first position). Assume that there are no duplicates in the list - every item is unique. #include <stdio.h> int findval(int size, int values[], int value); int main(void) { int arraysize =...; int result; int value =...; int myarray[] =...; result = findval(arraysize, myarray, value); if (result == -1) printf("the value %d is not in the list.\n", value); else printf("the value %d is at position %d in the list.\n", value, result); int findval(int size, int values[], int value) { int result, i; /* write the missing part below */ return result;

9 Sample Exam Problem. Write a recursive function that adds all the elements in an array. The function will take two arguments, 1) an integer value that is greater than 0 and indicates the size of the array, and 2) an integer array of that size. The function should return an integer value that is the sum of the elements in the array. The function should add elements of the input array using recursion and should not use a loop. #include <stdio.h> int recursivesum(int size, int values[]); int main(void) { int arraysize =...; int result; int myarray[] =...; result = recursivesum(arraysize, myarray); printf("the sum is %d\n", result); int recursivesum(int size, int values[]) { /* write the missing part below */

FORM 2 (Please put your name and form # on the scantron!!!!)

FORM 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. The amount of memory used by an array depends upon the array's data type and how many elements

More information

CS240: Programming in C. Lecture 3: More on Types

CS240: Programming in C. Lecture 3: More on Types CS240: Programming in C Lecture 3: More on Types Type representation and enforcement #include int main () { short s = 9; long l = 32768; short can store -32768 to 32767 printf("%d\n", s); s =

More information

Pointer Arithmetic B T W. *(array_ptr++) 1 vs (*array_ptr)++

Pointer Arithmetic B T W. *(array_ptr++) 1 vs (*array_ptr)++ Pointer Arithmetic When you add to or subtract from a pointer, the amount by which you do that is multiplied by the size of the type the pointer points to. In the case of our three increments, each 1 that

More information

This exam is to be taken by yourself with closed books, closed notes, no calculators.

This exam is to be taken by yourself with closed books, closed notes, no calculators. Student ID CSE 5A Name Final Signature Summer 2004 Page 1 (12) cs5a This exam is to be taken by yourself with closed books, closed notes, no calculators. Page 2 (33) Page 3 (32) Page 4 (27) Page 5 (40)

More information

Pointers Introduction. Spring 2012 Programming and Data Structure 1

Pointers Introduction. Spring 2012 Programming and Data Structure 1 Pointers Introduction Spring 2012 Programming and Data Structure 1 What is a pointer? Simple variables: An int / float variable is like a box which can store a single int value such as 42. num 42 A pointer

More information

CMPS 12B Introduction to Data Structures Summer 2012 Midterm Exam 2 Review Problems

CMPS 12B Introduction to Data Structures Summer 2012 Midterm Exam 2 Review Problems CMPS 12B Introduction to Data Structures Summer 2012 Midterm Exam 2 Review Problems 1. Write a recursive Java function called product(), which given a head reference to a linked list based on the Node

More information

Introduction to Systems Programming - COMP 1002, 1402

Introduction to Systems Programming - COMP 1002, 1402 POINTERS Introduction to Systems Programming - COMP 1002, 1402 Outline Memory Allocation Pointers in C Pointer and addresses Pointer Arithmetic Dynamic Memory Allocation Memory Allocation When you declare

More information

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING

UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING APS 105 Computer Fundamentals Midterm Examination October 18, 2012 6:15 p.m. 8:00 p.m. (105 minutes) Examiners: J. Anderson, B. Li, M. Sadoghi,

More information

Izmir Institute of Technology CE Lecture 8. References: - C: A software Engineering Approach 1

Izmir Institute of Technology CE Lecture 8. References: - C: A software Engineering Approach 1 Izmir Institute of Technology CE - 104 Lecture 8 References: - C: A software Engineering Approach 1 In this course you will learn Array assignment Pointer Arithmetic Passing Pointers as Function Arguments

More information

Data Types and Computer Storage Arrays and Pointers

Data Types and Computer Storage Arrays and Pointers Data Types and Computer Storage Arrays and Pointers K&R, chapter 5 Fundamental Data Types Most fundamental types are numeric (integer): - char - signed or unsigned - short int - signed or unsigned - int

More information

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE NOTE: IMPORTANT INSTRUCTIONS: 1. Question Paper in English and Hindi and Candidate can choose any one language. 2. In case of discrepancies in

More information

Section Mtg. Time Section Mtg. Time Section Mtg. Time A31 10:30 B36 1:30 C41 9:30 A32 11:30 B38 9:30 C42 11:30 A33 1:30 B39 12:30 C43 1:30 A34 2:30

Section Mtg. Time Section Mtg. Time Section Mtg. Time A31 10:30 B36 1:30 C41 9:30 A32 11:30 B38 9:30 C42 11:30 A33 1:30 B39 12:30 C43 1:30 A34 2:30 Midterm Exam II Engineering Problem Solving II, 59:6 (Version A) Name: Section: ( point) Question (5) 2 (5) 3 (5) 4 (6) 5 (6) 6 (4) 7 (6) 8 (6) 9 (5) Total Score Section Mtg. Time Section Mtg. Time Section

More information

INTI COLLEGE MALAYSIA

INTI COLLEGE MALAYSIA CSC112 (F) / Page 1 of 5 INTI COLLEGE MALAYSIA CERTIFICATE IN COMPUTING AND INFORMATION TECHNOLOGY PROGRAMME CSC 112 : FUNDAMENTALS OF PROGRAMMING FINAL EXAMINATION : DECEMBER 2002 SESSION This paper consists

More information

C Programming Basics. Ritu Arora Texas Advanced Computing Center June 21 st,

C Programming Basics. Ritu Arora Texas Advanced Computing Center June 21 st, C Programming Basics Ritu Arora Texas Advanced Computing Center June 21 st, 2012 Email: rauta@tacc.utexas.edu 1 Homework 5 (1) 1. #include 2. int main(){ 3. int i, j, k; 4. int mya[2][2] = {{1,

More information

PROGRAMMAZIONE I A.A. 2016/2017

PROGRAMMAZIONE I A.A. 2016/2017 PROGRAMMAZIONE I A.A. 2016/2017 FUNCTIONS INTRODUCTION AND MAIN All the instructions of a C program are contained in functions. üeach function performs a certain task. A special function name is main(

More information

CMPS 12B Introduction to Data Structures Midterm 2 Review Problems

CMPS 12B Introduction to Data Structures Midterm 2 Review Problems CMPS 12B Introduction to Data Structures Midterm 2 Review Problems 1. Write a recursive Java function called product(), which given a head reference to a linked list based on the Node class defined below,

More information

C Programming Part 2. Digital Design and Computer Architecture. David Money Harris and Sarah L. Harris. Copyright 2011 S. Harris and D.

C Programming Part 2. Digital Design and Computer Architecture. David Money Harris and Sarah L. Harris. Copyright 2011 S. Harris and D. C Programming Part 2 Digital Design and Computer Architecture David Money Harris and Sarah L. Harris C C Chapter :: Topics Function Calls Global vs. Local Variables More Data Types Pointers Arrays Characters

More information

CS Programming In C

CS Programming In C CS 24000 - Programming In C Week Three: Arrays, Strings, Pointers Zhiyuan Li Department of Computer Science Purdue University, USA Lab requirement on the main() function Announce: In order to get the autograder

More information

This exam is to be taken by yourself with closed books, closed notes, no calculators.

This exam is to be taken by yourself with closed books, closed notes, no calculators. Student ID CSE 5A Name Final Signature Fall 2003 Page 1 (12) cs5a This exam is to be taken by yourself with closed books, closed notes, no calculators. Page 2 (33) Page 3 (33) Page 4 (27) Page 5 (40) Page

More information

CS 2412 Data Structures. Chapter 1 Introduction

CS 2412 Data Structures. Chapter 1 Introduction CS 2412 Data Structures Chapter 1 Introduction 1 1.1 Basic concepts The basic idea of computer is to treat data: data input, data storage, data treatment, and data output. Data Structure 1. A combination

More information

Programming for Electrical and Computer Engineers. Pointers

Programming for Electrical and Computer Engineers. Pointers Programming for Electrical and Computer Engineers Pointers Dr. D. J. Jackson Lecture 11-1 Pointer Variables The first step in understanding pointers is visualizing what they represent at the machine level.

More information

Review Topics. Midterm Exam Review Slides. Number Representation What can a binary number mean? Number Representation Hexadecimal to Binary Conversion

Review Topics. Midterm Exam Review Slides. Number Representation What can a binary number mean? Number Representation Hexadecimal to Binary Conversion Review Topics Midterm Exam Review Slides Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University Base Conversion Floating-Point Math

More information

2-D Arrays UGM. Study Programs of Engineering Physics & Nuclear Engineering. Department of Engineering Physics, Faculty of Engineering

2-D Arrays UGM. Study Programs of Engineering Physics & Nuclear Engineering. Department of Engineering Physics, Faculty of Engineering 2-D Arrays COMPRO Department of Engineering Physics, Faculty of Engineering, Gadjah Mada University () Jl. Grafika 2, Yogyakarta 55281, (+62 274) 580882, http://www.tf.ugm.ac.id/ 1 2-D Arrays Introduction

More information

Arrays, Pointers, and Strings

Arrays, Pointers, and Strings Arrays, Pointers, and Strings Fall 2014 Jinkyu Jeong (jinkyu@skku.edu) 1 ARRAYS 2 Array An array is a set of subscripted variables of the same type int a[10]; char a[20]; Why we need arrays? Making code

More information

Lecture 3: Functions. Wednesday, 28 January 2009

Lecture 3: Functions. Wednesday, 28 January 2009 Lecture 3: Functions CS209 : Algorithms and Scientific Computing Lecturer: Niall Madden Wednesday, 28 January 2009 CS204/209 Lecture 3: Functions 1/24 Today... 1 Input: scanf() Note: 2 Input Checking if

More information

CSC 270 Survey of Programming Languages. What is a Pointer?

CSC 270 Survey of Programming Languages. What is a Pointer? CSC 270 Survey of Programming Languages C Lecture 6 Pointers and Dynamic Arrays What is a Pointer? A pointer is the address in memory of a variable. We call it a pointer because we envision the address

More information

Arrays and Pointers in C. Alan L. Cox

Arrays 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 information

1 (1x17 =17 points) 2 (21 points) 3 (5 points) 4 (3 points) 5 (4 points) Total ( 50points) Page 1

1 (1x17 =17 points) 2 (21 points) 3 (5 points) 4 (3 points) 5 (4 points) Total ( 50points) Page 1 CS 1621 MIDTERM EXAM 1 Name: Problem 1 (1x17 =17 points) 2 (21 points) 3 (5 points) 4 (3 points) 5 (4 points) Total ( 50points) Score Page 1 1. (1 x 17 = 17 points) Determine if each of the following statements

More information

In C Language, arrays start at position 0. So, int min [9] :

In C Language, arrays start at position 0. So, int min [9] : Birla Institute of Technology & Science, Pilani Computer Programming (CSF111) Second Semester 2015-2016 Lab Week 7 ------------------------------------------------------------------------------------------------------------------

More information

2.1 Arrays. Department of CSE

2.1 Arrays. Department of CSE 2.1 Arrays 1 Department of CSE Objectives To define an array, initialize an array and refer to individual elements of an array. To define symbolic constants. To define and manipulate multiple-subscripted

More information

Jeopardy! Assembly and Memory. 10 pts 10 pts 10 pts 10 pts 10 pts 10 pts. 20 pts 20 pts 20 pts 20 pts 20 pts 20 pts

Jeopardy! Assembly and Memory. 10 pts 10 pts 10 pts 10 pts 10 pts 10 pts. 20 pts 20 pts 20 pts 20 pts 20 pts 20 pts EC310 6-week Review Rules of Engagement Teams selected by instructor Host will read the entire questions. Only after, a team may buzz by raise of hand A team must answer the question within 5 seconds after

More information

Week 8: Arrays and File I/O. BJ Furman 11MAR2010

Week 8: Arrays and File I/O. BJ Furman 11MAR2010 Week 8: Arrays and File I/O BJ Furman 11MAR2010 The Plan for Today Arrays What is an array? How do you declare and initialize an array? How can you use an array? Array Examples Array Practice File I/O

More information

Arrays and Pointers. Lecture Plan.

Arrays and Pointers. Lecture Plan. . Lecture Plan. Intro into arrays. definition and syntax declaration & initialization major advantages multidimensional arrays examples Intro into pointers. address and indirection operators definition

More information

Indian Institute of Technology, Delhi

Indian Institute of Technology, Delhi Indian Institute of Technology, Delhi FALL, 2016 NOTE: COL 100: INTRODUCTION TO PROGRAMMING Minor 2 One Hour All answers need to be brief and to the point. Please make any assumptions that you deem to

More information

CS2311 Computer Programming

CS2311 Computer Programming CS2311 Computer Programming Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT9: Pointer I Outlines Memory and Variable Pointer and its operation Call by reference 2 Outcomes Explain the

More information

15IT102 Program Design and Development. John Blesswin (101922) Department of Computer Science and Engineering SRM University

15IT102 Program Design and Development. John Blesswin (101922) Department of Computer Science and Engineering SRM University 15IT102 Program Design and Development John Blesswin (101922) Department of Computer Science and Engineering SRM University Book to follow Programming in ANSI C 5th Edition by E. Balagurusamy Let us C

More information

CSRU 1600 Computer Science 1 Summer 2009 Review Questions (Midterm) 2.2) State whether each of the following is true or false. If false, explain why.

CSRU 1600 Computer Science 1 Summer 2009 Review Questions (Midterm) 2.2) State whether each of the following is true or false. If false, explain why. CSRU 1600 Computer Science 1 Summer 2009 Review Questions (Midterm) Chapter 2 2.1) Fill in the blanks in each of the following. a) Every C++ program begins execution at the function. b) A begins the body

More information

Outline. Lecture 1B C primer What we will cover. Like Java, like C. Simple Data Types

Outline. Lecture 1B C primer What we will cover. Like Java, like C. Simple Data Types Lecture 1B 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 1 Datorarkitektur 2006

More information

In while loop control statement, loop is executed until condition becomes false.

In while loop control statement, loop is executed until condition becomes false. BITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER 2015-2016 COURSE : COMPUTER PROGRAMMING (CS F111) Example program (for loop) in C: In for loop control statement, loop

More information

Pointers and Memory 9/29/16

Pointers and Memory 9/29/16 Pointers and Memory 9/29/16 Recall: Allocating (Heap) Memory The standard C library (#include ) includes functions for allocating memory void *malloc(size_t size) Allocate size bytes on the heap

More information

Principles of Programming Languages Topic: Imperative Programming II Professor Lou Steinberg Fall 2004

Principles of Programming Languages Topic: Imperative Programming II Professor Lou Steinberg Fall 2004 Principles of Programming Languages Topic: Imperative Programming II Professor Lou Steinberg Fall 2004 CS 314, LS, BR, LTM: Imperative Programming 1 Review Imperative programming: based on underlying machine:

More information

Section A: 2 Mark Questions

Section A: 2 Mark Questions Full marks: 100 Indian Institute of Technology, Kharagpur Computer Science and Engineering Department Mid-Semester Examination, Autumn 2012-13 Programming & Data Structures (CS 11002) Time: 2 hours Name

More information

Sample Examination. COMP1917 Higher Computing 1

Sample Examination. COMP1917 Higher Computing 1 Family Name:... Other Names:... Signature:... Student Number:... THE UNIVERSITY OF NEW SOUTH WALES SCHOOL OF COMPUTER SCIENCE AND ENGINEERING Sample Examination COMP1917 Higher Computing 1 Exam Duration:

More information

Arrays and Pointers (part 1)

Arrays and Pointers (part 1) Arrays and Pointers (part 1) EECS 2031 25 September 2016 1 Arrays l Grouping of data of the same type. l Loops commonly used for manipulation. l Programmers set array sizes explicitly. 2 1 Arrays: Example

More information

Introduction to Systems Programming - COMP 1002, 1402

Introduction to Systems Programming - COMP 1002, 1402 FUNCTION AND PROCEDURES Introduction to Systems Programming - COMP 1002, 1402 Outline Why Function? What is function? How to use functions? Libraries Function call Variables Scope Developing Large Programs

More information

C Arrays. Systems Programming

C Arrays. Systems Programming C Arrays Systems Programming Arrays Arrays Defining and Initializing Arrays Array Example Subscript Out-of of-range Example Passing Arrays to Functions Call by Reference Multiple-Subscripted Arrays Double-Subscripted

More information

What is Function in C Language?

What is Function in C Language? By Trupthi.M Asst.Prof, IT Department, CBIT, Gandipet, Hyderabad What is Function in C Language? A function in C language is a block of code that performs a specific task. It has a name and it is reusable

More information

Introduction to C. Systems Programming Concepts

Introduction to C. Systems Programming Concepts Introduction to C Systems Programming Concepts Introduction to C A simple C Program Variable Declarations printf ( ) Compiling and Running a C Program Sizeof Program #include What is True in C? if example

More information

Lecture 5 Notes: Pointers

Lecture 5 Notes: Pointers Introduction to C++ January 12, 2011 Massachusetts Institute of Technology 6.096 Lecture 5 Notes: Pointers 1 Background 1.1 Variables and Memory When you declare a variable, the computer associates the

More information

[1.4] First Simple Linked List in C Let us create a simple linked list with 3 nodes.

[1.4] First Simple Linked List in C Let us create a simple linked list with 3 nodes. Birla Institute of Technology & Science, Pilani Computer Programming (CS F111) Second Semester 2015-2016 Lab Sheet # 12 & 13 ------------------------------------------------------------------------------------------------------------------

More information

Catch a number from the keyboard, if it s equal to one, print out test 1 ; if it s equal to two, print out test 2 ; if it s equal to three, print out

Catch a number from the keyboard, if it s equal to one, print out test 1 ; if it s equal to two, print out test 2 ; if it s equal to three, print out Catch a number from the keyboard, if it s equal to one, print out test 1 ; if it s equal to two, print out test 2 ; if it s equal to three, print out test 3 ; for all other values, print out test 4. {

More information

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring 2015

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring 2015 United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring 2015 1. Do a page check: you should have 8 pages including this cover sheet. 2. You have 50 minutes

More information

Reference slides! Garcia, Fall 2011 UCB! CS61C L04 Introduction to C (pt 2) (1)!

Reference slides! Garcia, Fall 2011 UCB! CS61C L04 Introduction to C (pt 2) (1)! Reference slides! You ARE responsible for the material on these slides (they re just taken from the reading anyway). These were the slides that generated the fewest questions in years past (i.e., those

More information

Topic 4: C Data Structures

Topic 4: C Data Structures Topic 4: C Data Structures CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University of California, San Diego Arrays Declaration:

More information

Example: Passing a 1-D Array to a Function

Example: Passing a 1-D Array to a Function Sample Program Example: Passing a 1-D Array to a Function #include #define SIZE 3 void myfun (int a, int P[]); int (void) { int a = 2; int M[SIZE] = {3, 6, 9}; /* M is an array variable */ printf("1

More information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 9

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 9 BIL 104E Introduction to Scientific and Engineering Computing Lecture 9 Pointer Expressions and Pointer Arithmetic Pointer arithmetic is a convenient way for changing the value of a pointer in increments

More information

Arrays C programming. Reference: AL Kelly, (2012) A Book on C, Programming in C

Arrays C programming. Reference: AL Kelly, (2012) A Book on C, Programming in C Arrays C programming Reference: AL Kelly, (2012) A Book on C, Programming in C Objectives At the end of this Training the Programmer can: Demonstrate the parts of an array. Create an array declaration.

More information

C functions. Rolling your own

C functions. Rolling your own C functions Rolling your own Why functions? Encourage modular development Concentrate on one problem at a time Reusable code Write code once, use many times Can improve readability of code Function Named

More information

Dept. of Computer Engineering Final Exam, Second Semester: 2008/2009

Dept. of Computer Engineering Final Exam, Second Semester: 2008/2009 Philadelphia University Faculty of Engineering Student Name: Student Number: Dept. of Computer Engineering Final Exam, Second Semester: 2008/2009 Course Title: C++ Programming Date: 28/5/2009 Course No:

More information

Announcements. Program #1A. Reading. due Thursday. Chapter 1-4 & 7 (skip 7.6) Chapter 10 (by Thursday, skip 10.2) CMSC 212 S05 (lect 4)

Announcements. Program #1A. Reading. due Thursday. Chapter 1-4 & 7 (skip 7.6) Chapter 10 (by Thursday, skip 10.2) CMSC 212 S05 (lect 4) Announcements Program #1A due Thursday Reading Chapter 1-4 & 7 (skip 7.6) Chapter 10 (by Thursday, skip 10.2) 1 Storage Class and Linkage Review extern int b; static int c; Int func1(int e) { static int

More information

Introduction to C. Acknowledgement: These slides are adapted from lecture slides made available by Prof. Dave O Halloran (Carnegie Mellon University)

Introduction to C. Acknowledgement: These slides are adapted from lecture slides made available by Prof. Dave O Halloran (Carnegie Mellon University) Introduction to C Acknowledgement: These slides are adapted from lecture slides made available by Prof. Dave O Halloran (Carnegie Mellon University) 1 Outline Overview comparison of C and Java Good evening

More information

C - 3. Pointer expressions as L-values or R-values How to pass back values from functions? Casting. C3, CS314 Fall 01, BGR 1

C - 3. Pointer expressions as L-values or R-values How to pass back values from functions? Casting. C3, CS314 Fall 01, BGR 1 C - 3 Pointer expressions as L-values or R-values How to pass back values from functions? Casting To simulate subtyping Unsafe capabilities Pointer arithmetic Input with scanf() C3, CS314 Fall 01, BGR

More information

Pointer Fund am entals

Pointer Fund am entals Pointers Pointer Fund am entals When a variable is defined the compiler (linker/ loader actually) allocates a real memory address for the variable. int x; will allocate 4 bytes in the main memory, which

More information

Pointers and dynamic memory management in C

Pointers and dynamic memory management in C Pointers and dynamic memory management in C Jakob Rieck Proseminar C - 2014 Contents 1 Introduction 2 2 Pointers 4 2.1 Declaration & Initialization................... 5 2.2 Using pointers..........................

More information

Midterm CSE 2031, Summer 2010 June 8, 2010 YORK UNIVERISTY DEPARTMRENT OF COMPUTER SCIENCE AND ENGINEERING. Midterm CSE 2031 Software Tools

Midterm CSE 2031, Summer 2010 June 8, 2010 YORK UNIVERISTY DEPARTMRENT OF COMPUTER SCIENCE AND ENGINEERING. Midterm CSE 2031 Software Tools YORK UNIVERISTY DEPARTMRENT OF COMPUTER SCIENCE AND ENGINEERING Midterm CSE 2031 Software Tools June 8, 2010 SOLUTIONS Family Name: Given Name: CS account: Student Id: Instructions: 1. The exam has 10

More information

CS Programming In C

CS Programming In C CS 24000 - Programming In C Week Six: Review for Midterm 1 Zhiyuan Li Department of Computer Science Purdue University, USA Other Unary operators The indirection operator * is also called the pointer dereference

More information

The function prototype for printf in :

The function prototype for printf in <stdio.h>: 1 Hello.c /* gcc -Wall %1.c -o %1.exe Everything between /* and */ is a comment */ int main(void) printf("\nhello world"); Preprocessor statement Main function, begin function call to screen value returned

More information

2. Which of the following explicit data type conversions in the code above is unsafe? [A] (float) (b / a)

2. Which of the following explicit data type conversions in the code above is unsafe? [A] (float) (b / a) 1. Given that a and b are integer variables and both variables are currently storing a positive value, and a is greater than b, which of the following is FALSE about the result of a % b? [A]The result

More information

CMPS 11 Intermediate Programming Lab Assignment 7

CMPS 11 Intermediate Programming Lab Assignment 7 CMPS 11 Intermediate Programming Lab Assignment 7 The purpose of this assignment is to introduce the C programming language, including standard inputoutput functions. Begin by reading the first six chapters

More information

Functions Fall 2015 Jinkyu Jeong

Functions Fall 2015 Jinkyu Jeong Functions Fall 2015 Jinkyu Jeong (jinkyu@skku.edu) 1 Flow of Control Review Operators Relational Equality Logical short circuits Conditional operators if while for do while goto break & continue switch

More information

CMPE 108 SAMPLE FINAL EXAM QUESTIONS

CMPE 108 SAMPLE FINAL EXAM QUESTIONS CMPE 108 SAMPLE FINAL EXAM QUESTIONS PRECEDENCE AND ASSOCIATIVITY OPERATORS ASSOCIATIVITY ( ) [ ] Left to right! ++ -- + - (type) Right to left (Unary) * / % Left to right + - Left to right < >= Left

More information

Short Notes on Dynamic Memory Allocation, Pointer and Data Structure

Short Notes on Dynamic Memory Allocation, Pointer and Data Structure Short Notes on Dynamic Memory Allocation, Pointer and Data Structure 1 Dynamic Memory Allocation in C/C++ Motivation /* a[100] vs. *b or *c */ Func(int array_size) double k, a[100], *b, *c; b = (double

More information

Iosif Ignat, Marius Joldoș Laboratory Guide 7. Recursion RECURSION

Iosif Ignat, Marius Joldoș Laboratory Guide 7. Recursion RECURSION RECURSION 1. Overview The learning objective of this lab session is to: Understand the notion of recursion, the advantages and the shortcomings of recursive functions relative to the non-recursive ones,

More information

C: How to Program. Week /May/07

C: How to Program. Week /May/07 C: How to Program Week 11 2007/May/07 1 /* Fig. 6.11: fig06_11.c Static arrays are initialized to zero */ #include void staticarrayinit( void ); /* function prototype */ void automaticarrayinit(

More information

C and R programming: if-else In C, the general formats for these are,

C and R programming: if-else In C, the general formats for these are, C and R programming: if-else In C, the general formats for these are, An example would be: # include if( condition 1 ) statement1; else if( condition 2 ) statement2; else statement3; int i; printf("please

More information

Practice Exam for COMP 2355

Practice Exam for COMP 2355 Practice Exam for COMP 2355 Name: 1 of 1 Short Answer Problems [Problem 1] (4 points) Convert this binary number into the equivalent hexadecimal format: 1111 1110 1110 1101 1111 1010 1100 1110 [Problem

More information

Arrays (1A) Young Won Lim 1/14/17

Arrays (1A) Young Won Lim 1/14/17 Arrays (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 version

More information

Variables, types, and operators

Variables, types, and operators BUG_TRAP((int)tp->retrans_out >= 0); #endif if (tp->packets_out==0 && tp->sack_ok) if (tp->lost_out) printk(kern_debug "Leak l=%u %d\n", tp->lost_out, tp->ca_state); tp->lost_out = 0; if (tp->sacked_out)

More information

A whirlwind tour of C. Echtzeitsysteme WS 2014/2015

A whirlwind tour of C. Echtzeitsysteme WS 2014/2015 A whirlwind tour of C Echtzeitsysteme WS 2014/2015 heise@in.tum.de What you should already know The basic datatypes (e.g. int, float) Basic control flow (e.g. if/else, for, while) What functions are What

More information

1. Constants. 2. Variables. 3. Reserved words or key words. 4. Constants. Character set in C

1. Constants. 2. Variables. 3. Reserved words or key words. 4. Constants. Character set in C Character set in C We should use only the following characters in writing a C program. These characters can be combined to create C words. Alphabet: A, B, C, D.. Z, a, b, c, d..z Numeric digits: 0, 1,

More information

Introduction to Pointers in C. Address operator. Pointers. Readings: CP:AMA 11, 17.7

Introduction to Pointers in C. Address operator. Pointers. Readings: CP:AMA 11, 17.7 Introduction to Pointers in C Readings: CP:AMA 11, 17.7 CS 136 Winter 2017 06: Pointers 1 Address operator C was designed to give programmers low-level access to memory and expose the underlying memory

More information

Pointers. Better than sliced bread! Similar to Java references Java code example: myx = new X(); myx

Pointers. Better than sliced bread! Similar to Java references Java code example: myx = new X(); myx 1 Better than sliced bread! Similar to Java references Java code example: myx = new X(); Pointers myx 2 Assume the X object instance fits in the box myx 3 19 20 20 42060 (myx) 4 Java code: myx.dosomething(13);

More information

A whirlwind tour of C++

A whirlwind tour of C++ A whirlwind tour of C++ Echtzeitsysteme WS 2012/2013 heise@in.tum.de What you should already know What you should already know The basic datatypes (e.g. int, float) What you should already know The basic

More information

C Programming 9/8/2016

C Programming 9/8/2016 C Programming 9/8/2016 Announcements Written homework #1 is due by 4pm tomorrow. Figure out your partner for future labs by Tuesday. There will be a Piazza post with more information. From Tuesday: how

More information

ECE 551 PRACTICE Midterm Exam

ECE 551 PRACTICE Midterm Exam ECE 551 PRACTICE Midterm Exam This is a full length practice midterm exam. If you want to take it at exam pace, give yourself 75 minutes to take the entire test. Just like the real exam, each question

More information

Arrays, Pointers and Arithmetic

Arrays, Pointers and Arithmetic Arrays, Pointers and Arithmetic COMP 1402/1002 The Name of an Array 1 The Name of an Array /* the name of an array is a pointer value */ int a[5]; printf( %p %p, &(a[0]), a); The two values printed are

More information

C PROGRAMMING Lecture 3. 1st semester

C PROGRAMMING Lecture 3. 1st semester C PROGRAMMING Lecture 3 1st semester 2016-2017 Functions Functions Modules in C Programs combine user-defined functions with library functions C standard library has a wide variety of functions Function

More information

CS 31: Intro to Systems C Programming. Kevin Webb Swarthmore College January 28, 2016

CS 31: Intro to Systems C Programming. Kevin Webb Swarthmore College January 28, 2016 CS 31: Intro to Systems C Programming Kevin Webb Swarthmore College January 28, 2016 Reading Quiz Agenda Basics of C programming Comments, variables, print statements, loops, conditionals, etc. NOT the

More information

Functions. Functions. Design and Abstraction. Design and Abstraction

Functions. Functions. Design and Abstraction. Design and Abstraction Functions Functions Here is a simple program with two functions: Have you seen C functions before? Yes! We ve been working with the main function from the very beginning, as well as, printf, scanf, etc.,

More information

Example Solution to Exam in EDA150 C Programming

Example Solution to Exam in EDA150 C Programming Example Solution to Exam in EDA150 C Programming Janurary 12, 2011, 14-19 Inga hjälpmedel! Examinator: Jonas Skeppstedt, tel 0767 888 124 30 out of 60p are needed to pass the exam. General Remarks A function

More information

LESSON 7. ptr = &i; ptr = 0; ptr = NULL; /* equivalent to ptr == 0; */ ptr = (int *) 1999; /* an absolute address in memory */

LESSON 7. ptr = &i; ptr = 0; ptr = NULL; /* equivalent to ptr == 0; */ ptr = (int *) 1999; /* an absolute address in memory */ LESSON 7 POINTERS AND CALL BY REFERENCE When an expression is passed as an argument to a function, a copy of the value of the expression is made, and it is this copy that is passed to the function. Suppose

More information

December 01, Duration: 95 minutes X X - X X X

December 01, Duration: 95 minutes X X - X X X Lecturers: EASTERN MEDITERRANEAN UNIVERSITY Computer Engineering Department CMPE-231 --- DATA STRUCTURES MIDTERM EXAMINATION / FALL 2005-2006 Dr. Konstantin Degtiarev (groups 1 and 2) Prof. Erden Başar

More information

Learning style reminder

Learning style reminder Learning style reminder Please answer honestly: Have you written from scratch at least two short programs with each of these? if switch case while do while for rand() and srand() Learning style reminder

More information

C language topics (page 2)

C language topics (page 2) Compiling with C cc [-g] [-o file] [-DNAME[=VAL]...] [-IDIR...] file.c... [-lx] [ ] - Brackets not part of command [ ] - what is inside is optional... - last item repeats as many times as you want -g -

More information

MIT Aurangabad FE Computer Engineering

MIT Aurangabad FE Computer Engineering MIT Aurangabad FE Computer Engineering Unit 1: Introduction to C 1. The symbol # is called a. Header file c. include b. Preprocessor d. semicolon 2. The size of integer number is limited to a. -32768 to

More information

Final Exam Review. CS 1428 Fall Jill Seaman. Final Exam

Final Exam Review. CS 1428 Fall Jill Seaman. Final Exam Final Exam Review CS 1428 Fall 2011 Jill Seaman 1 Final Exam Friday, December 9, 11:00am to 1:30pm Derr 241 (here) Closed book, closed notes, clean desk Comprehensive (covers entire course) 25% of your

More information

Fisk University. Introduction to Computer Science II, Spring 2009 Homework on Quiz #2 (Due Friday, Feb 20 th, 2009)

Fisk University. Introduction to Computer Science II, Spring 2009 Homework on Quiz #2 (Due Friday, Feb 20 th, 2009) Fisk University Introduction to Computer Science II, Spring 2009 Homework on Quiz #2 (Due Friday, Feb 20 th, 2009) If your answer to a question on the quiz is incorrect, type the program given in the box

More information

The C Programming Language #include Intro to C. Basic Control Structures. About C

The C Programming Language #include <stdio.h> Intro to C. Basic Control Structures. About C The C Programming Language #include Intro to C C is a high-level language structured C is a low-level language machine access C is a small language, extendable with libraries C is permissive:

More information

ASSIGNMENT BOOKLET. M.Sc.(Mathematics with Applications in Computer Science) Programming and Data Structures

ASSIGNMENT BOOKLET. M.Sc.(Mathematics with Applications in Computer Science) Programming and Data Structures ASSIGNMENT BOOKLET MMT-001 M.Sc.(Mathematics with Applications in Computer Science) Programming and Data Structures (Valid from 1 st January, 2014 to 30 th November, 2014) It is compulsory to submit the

More information

Array of Strings COMPRO

Array of Strings COMPRO Array of Strings COMPRO Department of Engineering Physics, Faculty of Engineering, Gadjah Mada University () Jl. Grafika 2, Yogyakarta 55281, (+62 274) 580882, http://www.tf.ugm.ac.id/ 1 Array of Strings

More information