CSE 5A Final Fall 2006

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

Final CSE 131B Spring 2005

Final CSE 131B Spring 2004

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Introduction to C. Systems Programming Concepts

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Midterm CSE 131 Winter 2012

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

Midterm CSE 131B Spring 2005

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

Quiz1 Fall 2007 October 2 nd, UNIVERSITY OF WINDSOR Fall 2007 QUIZ # 1 Solution. Examiner:Ritu Chaturvedi Dated :October 2nd, 2007.

Signature: ECE 551 Midterm Exam

Midterm CSE 131 Winter 2013

EE 312 Fall 2017 Midterm 1 October 12, 2017

PRINCIPLES OF OPERATING SYSTEMS

CSE 30 Fall 2006 Final Exam

CSE 11 Final Fall 2009

C: How to Program. Week /Mar/05

ECE264 Fall 2013 Exam 1, September 24, 2013

Final CSE 131 Fall 2014

CSE 30 Fall 2012 Final Exam

Midterm CSE 131 Winter 2014

CS 61c: Great Ideas in Computer Architecture

Chapter 2 - Introduction to C Programming

CSE101-Lec#17. Arrays. (Arrays and Functions) Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming

COMP 208 Computers in Engineering

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef

UNIVERSITY OF WINDSOR Fall 2006 QUIZ # 1. Examiner:Ritu Chaturvedi Dated : Oct 3rd, Student Name: Student Number:

Floating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

Intermediate Programming, Spring 2017*

Q1: /20 Q2: /30 Q3: /24 Q4: /26. Total: /100

Unit 7. Functions. Need of User Defined Functions

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

CSC231 C Tutorial Fall 2018 Introduction to C

Note: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be.

A Fast Review of C Essentials Part I

Midterm CSE 131B Spring 2006

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

CSE 30 Fall 2007 Final Exam

Lecture 02 C FUNDAMENTALS

OBJECT ORIENTED PROGRAMMING

CS16 Exam #1 7/17/ Minutes 100 Points total

BİL200 TUTORIAL-EXERCISES Objective:

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

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

ESC101N: Fundamentals of Computing End-sem st semester

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

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

CSE 30 Fall 2013 Final Exam

Final CSE 131 Winter 2012

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

BSM540 Basics of C Language

Final Intro to C Review

CSE 30 Winter 2014 Final Exam

C programming basics T3-1 -

BLM2031 Structured Programming. Zeyneb KURT

Computers in Engineering. Moving From Fortran to C Michael A. Hawker

a) (5 points) What is the output of the following code sequence? int *ptr = 0x1050; printf ("%x\n", ptr--); printf ("%x\n", ptr);

Computer Science & Engineering 150A Problem Solving Using Computers

Compiling and Running a C Program in Unix

Computers Programming Course 5. Iulian Năstac

Final CSE 131 Winter 2010

Midterm CSE 131 Fall 2014

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

CSE 11 Midterm Fall 2008

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

Functions. Lab 4. Introduction: A function : is a collection of statements that are grouped together to perform an operation.

EE 312 Fall 2018 Midterm 1 Version A October 10, 2018

Computer Systems Programming. Practice Midterm. Name:

CS 61C: Great Ideas in Computer Architecture. C Arrays, Strings, More Pointers

The C Programming Language Part 4. (with material from Dr. Bin Ren, William & Mary Computer Science, and

Computer System and programming in C

C Programming Review CSC 4320/6320

AN OVERVIEW OF C. CSE 130: Introduction to Programming in C Stony Brook University

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

The University of Calgary. ENCM 339 Programming Fundamentals Fall 2016

ET156 Introduction to C Programming

Final CSE 131B Winter 2003

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

Fundamentals of Programming

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

Subject: Fundamental of Computer Programming 2068

Lecture 2: C Programming Basic

Decision Making -Branching. Class Incharge: S. Sasirekha

The C language. Introductory course #1

Guide for The C Programming Language Chapter 1. Q1. Explain the structure of a C program Answer: Structure of the C program is shown below:

EC 413 Computer Organization

Write a C program using arrays and structure

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park

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

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

CPE Summer 2015 Exam I (150 pts) June 18, 2015

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

Lecture 3: C Programm

Dalhousie University CSCI 2132 Software Development Winter 2018 Midterm Examination II March 12 15:37-16:24

JTSK Programming in C II C-Lab II. Lecture 3 & 4

CSE 30 Winter 2009 Final Exam

Transcription:

Student ID cs5f Name Signature CSE 5A Final Fall 2006 Page 1 (18 points) Page 2 (26 points) Page 3 (28 points) Page 4 (16 points) Page 5 (40 points) Page 6 (44 points) Total (172 points = 164 points + 8 points EC) This exam is to be taken by yourself with only your 2-sided notes, no electronic devices. 0

Operator Precedence Table Operators Associativity - (unary) ++ --! right to left * / % left to right + - left to right < <= > >= left to right ==!= left to right && left to right left to right = += -= *= /= right to left 1. Using the operator precedence table above, evaluate each expression and state what gets printed. int x = 3; int a = 16; int b = 11; x = b + x - b * x / a; printf( "%d\n", x ); (3 pts) int x = 3; int a = 16; int b = 11; x = a + b % x * x - b; printf( "%d\n", x ); (3 pts) 2. What gets printed in the following blocks of statements? int a = 4; int x = -3; int b = 5; int y = 10; int c = -7; int z = x + 9; if ( (c < b) &&!(a < b)!(c == a) ) if ( (z == y) (x < y) &&!(y <= z) ) printf( "True" ); printf( "True" ); else else printf( "False" ); printf( "False" ); (3 pts) (3 pts) 3. Fill in the blanks for the appropriate compilation sequence. (6 pts) A) C Compiler D) Executable Program B) C Preprocessor E) Linker/Linkage Editor C) C Source Code F) Assembler > > > > > 1

4. Which of the following are not valid C identifiers? Circle the incorrect identifiers. (16 pts) [+1 if correct; -1 if incorrect] for 1stOne Nine_2_Five Big1 Nine_To_Five Nine-To-Five Fill in the blanks with the appropriate types and format specifiers to output the values correctly. int main( void ) a = '2'; b = 2; c = "CSE 5A"; d = 4.20; printf( "b = % \nd = % \nc = % \na = % \n", b, d, c, a ); printf( "c[% ] = \'% \'\n", b, c[b] ); return 0; What does that last printf() statement output? 5. Write a function called checkrange that checks if the first argument is between the second and third arguments exclusive. You can assume the second argument is less than or equal to the third argument. Return the integer value 1 to indicate YES (the first argument is between the second and third argument); return the integer value 0 to indicate NO (the first argument is not between the second and third argument). Fill in the blanks to complete this function. (10 pts) Examples: checkrange( 10, 10, 20 ) would return 0 checkrange( 8, 10, 20 ) would return 0 checkrange( 30, 20, 30 ) would return 0 checkrange( 43, -9, 33 ) would return 0 checkrange( 25, 22, 44 ) would return 1 checkrange( 19, 19, 19 ) would return 0 checkrange( int value, int minvalue, int maxvalue ) if ( ) return 0; else ; 2

6. Write an equivalent while loop for the following for loop. (12 pts) Equivalent while int num, result; // Do not change int num, result; // Same as the for loop for ( num = 7; num < 100; num = num * 3 ) result = foo( num ); printf( "%d %d\n", result, num ); 7. What gets printed in the following block of statements? (8 pts) #define SIZE 8 int i; int array[size] = -11, 2, 14, 4, 12, 3, 24, 10 ; for ( i = 0; i < SIZE; ++i ) if ( (array[i] * 2) < 20 ) printf( "%d\n", array[i] ); 8. What gets printed? (8 pts) #include <stdio.h> int function1( double param1, int param2 ); void main( void ) double i = 6.69; int j = 5; j = function1( i, j ); printf( "%d\n", j ); return 0; int function1( double param1, int param2 ) int i; for ( i = 8; i > param2; --i ) printf( "%.2f\n", param1 + i ); return (param2 + i); 3

9. What gets printed? (16 pts) #include <stdio.h> #define SIZE 8 char notjenny( int x ); int main( void ) char answer[size]; int i; for ( i = 0; i < SIZE; ++i ) answer[i] = notjenny( i ); for ( i = 0; i < SIZE; ++i ) printf( "%c\n", answer[i] ); return 0; char notjenny( int x ) char str[size] = 'f', 'a', 'g', 'r', 'p', 'o', 'u', 'e' ; if ( (x % 2)!= 1 ) return ( str[(x + 3) % SIZE] ); else return ( str[(x + 5) % SIZE] ); 4

10. Consider the following program. Identify the marked parts, lifetime, and scope/visibility with the corresponding letter/digit from the lists below. (40 pts) C/C++ Program Part Lifetime Scope/Visibility A) C Preprocessor Directive 1) During foo() call WW) Within func2() Only B) External Static Variable 2) Entire Program XX) Just This Source Module C) Function Prototype 3) During func2() call YY) Within foo() Only D) Function Definition ZZ) Entire Program E) (Formal) Parameter F) Internal Static Variable G) Local Variable H) Global Variable C/C++ Program Part Lifetime Scope/Visibility #include <stdio.h> #define SIZE 17 int func2( char array[] ); (entire line) static long johns; double ch = 4.20; void foo( char ch ) (foo()...) (ch) int actor; static int answer; /* Other code here */ static int func2( char fubar[] ) (func2()...) (fubar) int result = 19; static char johns = 'A'; /* Other code here */ How many times is the variable result in func2() initialized to 19 if func2() is called 6 times? time(s) What is the initial value of the variable answer in foo()? How many times is the variable answer in foo() given this value if foo() is called 6 times? time(s) What is the initial value of the variable actor in foo()? How many times is the variable johns in func2() initialized if func2() is called 6 times? time(s) Code in foo() that refers to the symbol/name johns refers to which symbol/name (state the type)? Code in func2() that refers to the symbol/name johns refers to which symbol/name (state the type)? 5

11. Consider the following structure definition and variable declarations. (20 pts) struct Almost_Done int a[5]; float b[11]; int c; char d[100]; int e; ; struct Almost_Done var1, var2, var3; Fill in the blanks to complete the following tasks: /* Read the value typed at the keyboard into the struct member e in var1 */ scanf( "% \n", ); /* Print all elements of struct member b in var2 EXCEPT the first and last elements */ for ( i = ; i < ; ) printf( "% \n", ); /* Put the answer to what is my favorite beer in struct member d in var3 */ str (, ); (complete this function) 12. Consider the following strings variable definitions. (24 pts) char s1[] = " of Suburbia"; char s2[] = "Jesus"; char s3[40]; char s4[20] = "Green Bay"; char s5[] = "-Land!"; strcpy( s3, s2 ); strcat( s3, s1 ); What gets printed? printf( "%d", sizeof( s1 ) ); printf( "%d", strlen( s3 ) ); Fill in the blanks to complete the following tasks: /* Change the 'B' in s4 to 'D' without using an explicit 'D' or 'd' */ = ; /* CANNOT use 'D' or 'd' */ /* Output "Green Day Jesus of Suburbia!" in a single printf() statement. */ printf( "% % % % ",,,, ); (space) 6

Scratch Paper 7

Scratch Paper 8