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

Similar documents
CSE 5A Final Fall 2006

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

Final CSE 131B Spring 2004

Final CSE 131B Spring 2005

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

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

Midterm CSE 131 Winter 2013

Introduction to C. Systems Programming Concepts

Midterm CSE 131 Winter 2014

CSE 30 Fall 2012 Final Exam

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

Final CSE 131 Fall 2014

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

CSE 30 Fall 2013 Final Exam

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

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

C programming basics T3-1 -

C: How to Program. Week /Mar/05

Final CSE 131 Winter 2010

ECE264 Fall 2013 Exam 1, September 24, 2013

Signature: ECE 551 Midterm Exam

Midterm CSE 131B Spring 2006

Chapter 2 - Introduction to C Programming

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

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

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

BSM540 Basics of C Language

PRINCIPLES OF OPERATING SYSTEMS

BLM2031 Structured Programming. Zeyneb KURT

Compiling and Running a C Program in Unix

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

A Fast Review of C Essentials Part I

Midterm CSE 131 Fall 2014

Final CSE 131B Winter 2003

CSC231 C Tutorial Fall 2018 Introduction to C

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

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

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

OBJECT ORIENTED PROGRAMMING

CSE 30 Winter 2014 Final Exam

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

Computers Programming Course 5. Iulian Năstac

ESC101N: Fundamentals of Computing End-sem st semester

BİL200 TUTORIAL-EXERCISES Objective:

EE 312 Fall 2017 Midterm 1 October 12, 2017

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

CSE 30 Fall 2007 Final Exam

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

Fundamentals of Programming

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

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Questions Bank. 14) State any four advantages of using flow-chart

Computer Science & Engineering 150A Problem Solving Using Computers

The University of Calgary. ENCM 339 Programming Fundamentals Fall 2016

Final Intro to C Review

Intermediate Programming, Spring 2017*

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

Final CSE 131 Fall 2015

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

C Programming Review CSC 4320/6320

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

AMCAT Automata Coding Sample Questions And Answers

COMP 208 Computers in Engineering

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

Unit 7. Functions. Need of User Defined Functions

CSE 30 Fall 2006 Final Exam

6.096 Introduction to C++ January (IAP) 2009

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

UNIVERSITY OF WINDSOR Winter 2007 QUIZ # 1 Solution. Examiner:Ritu Chaturvedi Dated : Feb 7 th, Student Name: Student Number:

C Introduction. Comparison w/ Java, Memory Model, and Pointers

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

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

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

A3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH 'C' LANGUAGE

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

Final CSE 131 Winter 2012

CSE 30 Spring 2007 Final Exam

CS 61c: Great Ideas in Computer Architecture

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

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

Final Exam 1 /12 2 /12 3 /10 4 /7 5 /4 6 /10 7 /8 8 /9 9 /8 10 /11 11 /8 12 /10 13 /9 14 /13 15 /10 16 /10 17 /12. Faculty of Computer Science

It is necessary to have a single function main in every C program, along with other functions used/defined by the programmer.

Programming and Data Structures

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

CSCI 171 Chapter Outlines

Chap 0: Overview. Overview of basic C++ syntax Refresh programming basics C++ Vs. Java differences Coding conventions used. EECS 268 Programming II 1

CSE 30 Spring 2006 Final Exam

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

CS240: Programming in C

PERIYAR CENTENARY POLYTECHNIC COLLEGE Periyar Nagar- Vallam Thanjavur

M1-R4: Programing and Problem Solving using C (JULY 2018)

Unit 1: Introduction to C Language. Saurabh Khatri Lecturer Department of Computer Technology VIT, Pune

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

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

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

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

Course Outline Introduction to C-Programming

Transcription:

Student ID CSE 5A Name Final Signature Fall 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) Page 6 (42) Operator Precedence Table Total (177 + 9 EC = 186) 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 = a + b % x * x - b; printf( "%d\n", x ); (3 pts) int x = 3; int a = 16; int b = 11; x = b + x - b * x / a; 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 ( (a < 6) &&!(b < 8)!(c!= a) ) if ( (z == 8)!(x > y) && (y >= z) ) printf( "True" ); printf( "True" ); else else printf( "False" ); printf( "False" ); (3 pts) (3 pts) 1

3. Fill in the blanks for the appropriate compilation sequence. (6 pts) A) Executable Program D) C Compiler B) Linker/Linkage Editor E) C Preprocessor C) Assembler F) C Source Code > > > > > 4. Now match what various parts of the compilation sequence does. The letters above may be used more than once or not at all. (12 pts) Translates a program written in assembly language into an equivalent program represented in machine code (0's and 1's) Expands #include and #define statements Translates a program written in C language into an equivalent program represented in assembly language Strips away comments Brings all the object modules together including those from the Standard C Library used in your program and produces a file that can be executed Performs syntax (form/structure) and semantic (meaning) analysis of your program 5. Write a function called checkrange that checks if the first argument is between the second and third arguments inclusive. 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. (15 pts) Examples: checkrange( 10, 10, 20 ) would return 1 checkrange( 8, 10, 20 ) would return 0 checkrange( 30, 20, 30 ) would return 1 checkrange( 43, -9, 33 ) would return 0 checkrange( 25, 22, 44 ) would return 1 checkrange( 19, 19, 19 ) would return 1 checkrange( int value, int minvalue, int maxvalue ) if ( && ) return 1; else ; 2

6. Write an equivalent switch statement for the following if-else statement. (16 pts) Equivalent switch if ( x == 5 x == 18 ) x = x + 23; printf( "%d", x ); else if ( x == -7 ) x = 420 / x; else printf( "Switchfoot" ); x = 666 * 0; 7. What gets printed in the following block of statements? (8 pts) #define SIZE 8 int i; int array[size] = -11, 2, 7, 4, 6, 3, 12, 5 ; for ( i = 0; i < SIZE; ++i ) if ( (array[i] * 2) >= 10 ) printf( "%d\n", array[i] ); 8. What gets printed? (8 pts) #include <stdio.h> int function1( float param1, int param2 ); void main( void ) float i = 3.14; int j = 3; j = function1( i, j ); printf( "%d\n", j ); int function1( float param1, int param2 ) int i; for ( i = 1; i <= param2; ++i ) printf( "%.2f\n", param1 + i ); return (param2 * i); 3

9. What gets printed? (27 pts) #include <stdio.h> #define SIZE 7 int function2( int array[], int size ); void main( void ) int array[size] = -2, 1, 4, 2, 3, -3, 6 ; int i, result; result = function2( array, SIZE ); printf( "Returned value = %d\n", result ); printf( "Array elements:\n" ); for ( i = 0; i < SIZE; ++i ) printf( "%d\n", array[i] ); int function2( int array[], int size ) int i; int count = size; for ( i = size - 1; i > 0; --i ) if ( array[i] >= array[i-1] ) array[i] = 2 * array[i-1]; --count; return count; 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) Entire Program WW) Just This Source Module B) Global Variable 2) During func2() call XX) Within func2() Only C) Local Variable 3) During foo() call YY) Entire Program D) Function Definition ZZ) Within foo() Only E) Internal Static Variable F) (Formal) Parameter G) Function Prototype H) External Static Variable C/C++ Program Part Lifetime Scope/Visibility #include <stdio.h> #define SIZE 17 int func2( char array[] ); (entire line) static long actor; double ch = 4.20; void foo( char ch ) (foo()...) (ch) static int actor; int result = 8; /* Other code here */ static int func2( char fubar[] ) (func2()...) (fubar) static int result = 19; char actor; /* Other code here */ How many times is the variable result in func2() initialized to 19 if func2() is called 6 times? times What is the initial value of the variable actor in foo()? How many times is the variable actor in foo() given this value if foo() is called 6 times? times What is the initial value of the variable actor in func2()? How many times is the variable result in foo() initialized if foo() is called 6 times? times Code in foo() that refers to the symbol/name actor refers to which symbol/name? Code in func2() that refers to the symbol/name actor refers to which symbol/name? 5

11. Consider the following structure definition and variable declarations. (18 pts) struct Almost_Done float a; int b; float c[9]; int d[5]; 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 b in var1 */ scanf( "% \n", ); /* Print all elements of struct member c in var2 EXCEPT the first and last elements */ for ( i = ; i < ; ) printf( "% \n", ); /* Assign the number of licks it takes to get to the center of a tootsie pop to the last element in struct member d in var3 */ = ; 12. Consider the following strings variable definitions. (24 pts) char s1[] = " for an "; char s2[] = "Eye"; char s3[40]; char s4[20] = "UNCLE"; char s5[] = "unknown"; strcpy( s3, s2 ); strcat( s3, s1 ); What gets printed? printf( "%d", strlen( s3 ) ); printf( "%d", sizeof( s1 ) ); Fill in the blanks to complete the following tasks: /* Change the 'C' in s4 to 'K' without using an explicit 'K' */ = ; /* CANNOT use 'K' */ /* Output "UNKLE Eye for an Eye" in a single printf() statement. */ printf( "% % % % ",,,, ); 6

Scratch Paper 7

Scratch Paper 8