CS-211 Fall 2017 Test 1 Version A Oct. 2, Name:

Similar documents
CS-211 Fall 2017 Test 1 Version Practice For Test on Oct. 2, Name:

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:

CS-220 Spring 2018 Test 1 Version A Feb. 28, Name:

CS-140 Fall 2017 Test 1 Version Practice Practie for Sept. 27, Name:

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

CS2141 Software Development using C/C++ C++ Basics

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

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

CpSc 1010, Fall 2014 Lab 10: Command-Line Parameters (Week of 10/27/2014)

Presented By : Gaurav Juneja

Binghamton University. CS-211 Fall Data Conversion. software diversity in action

Variables in C. CMSC 104, Spring 2014 Christopher S. Marron. (thanks to John Park for slides) Tuesday, February 18, 14

Syntax and Variables

CS-211 Fall 2017 Test 2 Version A November 29, Name:

Today. o main function. o cout object. o Allocate space for data to be used in the program. o The data can be changed

Question 2. [5 points] Given the following symbolic constant definition

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

CSc Introduction to Computing

Procedures, Parameters, Values and Variables. Steven R. Bagley

Binghamton University. CS-211 Fall Functions. The Basis of C

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

Programming in C. Pointers and Arrays

Lecture 2 Tao Wang 1

Informatica e Sistemi in Tempo Reale

IT 1033: Fundamentals of Programming Data types & variables

Fundamentals of Programming

University of Maryland Baltimore County. CMSC 202 Computer Science II. Fall Mid-Term Exam. Sections

Creating, Compiling and Executing

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

Arithmetic Expressions in C

VARIABLES AND CONSTANTS

Programming. C++ Basics

Binghamton University. CS-120 Summer Introduction to C. Text: Introduction to Computer Systems : Chapters 11, 12, 14, 13

ECE 250 / CS 250 Computer Architecture. C to Binary: Memory & Data Representations. Benjamin Lee

CSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

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

CSE / ENGR 142 Programming I

Variables and literals

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Memory, Data, & Addressing II CSE 351 Spring

These are reserved words of the C language. For example int, float, if, else, for, while etc.

Integer Data Types. Data Type. Data Types. int, short int, long int

BASIC ELEMENTS OF A COMPUTER PROGRAM

Physics 234: Computational Physics

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

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

DHA Suffa University CS 103 Object Oriented Programming Fall 2015 Lab #01: Introduction to C++

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

CS 0449 Sample Midterm

C: How to Program. Week /Mar/05

CMSC 104 -Lecture 5 John Y. Park, adapted by C Grasso

Processor. Lecture #2 Number Rep & Intro to C classic components of all computers Control Datapath Memory Input Output

CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

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

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

The output: The address of i is 0xbf85416c. The address of main is 0x80483e4. arrays.c. 1 #include <stdio.h> 3 int main(int argc, char **argv) 4 {

Exercise Session 2 Simon Gerber

Chapter 2 - Introduction to C Programming

DEPARTMENT OF MATHS, MJ COLLEGE

COMP 2355 Introduction to Systems Programming

ECE264 Fall 2013 Exam 1, September 24, 2013

Computer Programming 3 th Week Variables, constant, and expressions

6. Control Statements II

CS242 COMPUTER PROGRAMMING

Coursework 2: Basic Programming

Lecture 2. Examples of Software. Programming and Data Structure. Programming Languages. Operating Systems. Sudeshna Sarkar

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

Language Reference Manual

CS240: Programming in C

Java Notes. 10th ICSE. Saravanan Ganesh

CHAPTER 5 VARIABLES AND OTHER BASIC ELEMENTS IN JAVA PROGRAMS

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Two s Complement Review. Two s Complement Review. Agenda. Agenda 6/21/2011

Pointers and scanf() Steven R. Bagley

This is CS50. Harvard University Fall Quiz 0 Answer Key

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

Design Patterns: State, Bridge, Visitor

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

In this session we will cover the following sub-topics: 1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.

CYSE 411/AIT681 Secure Software Engineering Topic #12. Secure Coding: Formatted Output

2/9/18. CYSE 411/AIT681 Secure Software Engineering. Readings. Secure Coding. This lecture: String management Pointer Subterfuge

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011

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

Language Design COMS W4115. Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science

Course Outline Introduction to C-Programming

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

Model Viva Questions for Programming in C lab

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)

Data Types and Variables in C language

Computer Components. Software{ User Programs. Operating System. Hardware

Computer System and programming in C

CS 106 Introduction to Computer Science I

C BOOTCAMP DAY 2. CS3600, Northeastern University. Alan Mislove. Slides adapted from Anandha Gopalan s CS132 course at Univ.

Sample Problems for Quiz # 2

Transcription:

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 program in file myprog.c, then I execute that program by typing./myprog.c. The C program must be compiled first... the.c code is not executable. (b) T F : If the main function of a C program returns the value 372, then the operating system knows that something went wrong in the execution of that code. Any non-zero return from main indicates an error. (c) T F : In ASCII encoding, every printable character maps to a number between 0 and 255. (d) T F : If a signed short integer in C can hold values between -32,768 and 32,767, then an unsigned short integer can hold values between 0 and 32,767. An unsigned short integer can hold values between 0 and 65,535. (e) T F : The char data type in C may refer to either the ASCII code for a single letter, or a number between -128 and +127, or a list of 8 bits. (f) T F : The arguments to the main function always have the same values, no matter how the program was invoked. Arguments to the main function depend on what was specified on the command line when the program was invoked. (g) T F : When a function is invoked, C first evaluates the argument expressions, then copies the results of those evaluations to the function parameters, then executes the function, and finally replaces the invocation with the return value of the function. (h) T F : In C, the assignment statement x=3; evaluates to the value 3, but that value is typically discarded. (i) T F : In C, a switch statement is used to switch between sequential instruction evaluation, and evaluation of every other instruction. A switch statement allows selection among several case statements depending on a comparison of a single variable to several different values. (j) T F : In C, a while(1) {... loop is an endless loop unless the loop body contains a break keyword. 2. (10 points) For the following, put a check in front of the statements that are valid declaration statements and will not cause a compiler error. int x=7; int x73=#seventy-three; big y=13845723; char w=742; floatx y=7.93e10; static double global x=3.72e19; char firstinitial=65; float temperature=83.2 long pi=3.1414; double onethirdoften = 10.0/3; Page 1 of 5

3. (10 points) Given the following declare statements: int x=17; f loat IF ; char small ; Put a check in front of the statements that are syntactically correct, and will not cause a compile error. x = 18; IF = 6.79e3; x = /* 3/0 */ x + 2; IF = /* /* 3/0 */ x/0 */ + IF * 3; x = a * 2; char init = T ; small = 3 * 110; int while=1; // int if x=7 x = small = (x+3); 4. (10 points) Given the following declarations: int a = 1 3 ; int b=4; int c =2; float fx =1.3; float fy = 7.0; Determine the value of the following C expressions. Make sure you include a decimal point for float values, but leave a decimal point out for integer values. (a) 21 = a + b * c (b) 1 = fy < fx (c) 1 = a % c (d) 1 = b < (fx+3.0) (e) -7 = fy > 0? 7:-7 (f) 0.0 = fy + 7 (g) 0 = (a<0) * b (h) 4.0 = 12-8.0 (i) 1 = b 17 (j) 0 = b & 1 5. (10 points) What does the following code print when compiled and executed? int a = 1 3 ; int x = 0 ; i f ( a > 0) { x++; i f (++x > 1) { x++; i f ( ( a < 0 ) && (++x > 3 ) ) { x++; p r i n t f ( x=%d\n, x ) ; x=3 Page 2 of 5

6. (10 points) What does the following code print if it is invoked as stats(69,249)? (Hint: Very little arithmetic is required to answer this question!) void s t a t s ( int h i t s, int atbats ) { int battingaverage = ( h i t s / atbats ) 1000; p r i n t f ( Batting average i s %d\n, battingaverage ) ; Batting avaerage is 0 7. (10 points) What does the following snippet of code produce when compiled and executed? int a = 1 3 ; // a i s 13 a = a // + 3 ; / a= 21 / 2 ; int c = / a + / 3 + / 4 / + 12 / 13 / ; / i f ( a<30) / { p r i n t f ( a=%d, c=%d\n, a, c ) ; // e l s e { p r i n t f ( a i s too big \n ) ; a=26, c=12 8. (10 points) Given the following C code: int x=1; i f ( x>0) i f (2==x%3) x =2; else i f (0==x%3) x =3; else x =5; p r i n t f ( x i s %d\n, x ) ; What will get printed to the terminal when this code is executed? x is 5 Page 3 of 5

9. (10 points) Given the following code: int main ( int argc, char argv ) { i f ( argc!=3) { p r i n t f ( Invoke as : %s <width> <height >\n, argv [ 0 ] ) ; double width=a t o f ( argv [ 1 ] ) ; i f ( width <=0 ) { p r i n t f ( The width, %s, has an i n v a l i d value o f %f \n, argv [ 1 ], width ) ; double h e i g h t=a t o f ( argv [ 2 ] ) ; i f ( height <=0 ) { p r i n t f ( The height, %s, has an i n v a l i d value o f %f \n, argv [ 2 ], height ) ; double area=width h e i g h t ; p r i n t f ( Width=%f h e i g h t=%f area=%f \n, width, height, area ) ; return 0 ; (a) If this is invoked as./area 2.5 4.0, what will get printed to the terminal window? Width=2.500000 height=4.000000 area=10.000000 (b) If this is invoked as./area 1.7, what will get printed to the terminal window? Invoke as./area <width> <height> (c) If this is invoked as./area 1.6 garbage, what will get printed to the terminal window? The height, garbage, has an invalid value of 0.000000 (d) If this is invoked as./area 3.0 5.0inches, what will get printed to the terminal window? Width=3.000000 height=5.000000 area=15.000000 10. (10 points) Write a function in C that takes three doubles; a, b, and c; as parameters, and returns the sum of a and b divided by c as a double precision floating point number. If c is zero, return 0.0. Solution: double c a l c ( double a, double b, double c ) { return ( c! = 0. 0 )? ( a+b )/ c : 0. 0 ; Page 4 of 5

Question: 1 2 3 4 5 6 7 8 9 10 Total Points: 10 10 10 10 10 10 10 10 10 10 100 Bonus Points: 0 0 0 0 0 0 0 0 0 0 0 Page 5 of 5