Midterm CSE 131 Fall 2015

Similar documents
Memory is implemented as an array of electronic switches

ASCII Code. Numerous codes were invented, including Émile Baudot's code (known as Baudot

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Xi2000 Series Configuration Guide

DEBT COLLECTION SYSTEM ACCOUNT SUBMISSION FILE

URL encoding uses hex code prefixed by %. Quoted Printable encoding uses hex code prefixed by =.

BI-300. Barcode configuration and commands Manual

Voyager 9520/40 Voyager GS9590 Eclipse 5145

The ASCII Character Set

Chapter 5. Binary, octal and hexadecimal numbers

Symbols in subject lines. An in-depth look at symbols

Chapter 1. Binary, octal and hexadecimal numbers

BARCODE READER V 2.1 EN USER MANUAL

This is great when speed is important and relatively few words are necessary, but Max would be a terrible language for writing a text editor.

BAR CODE 39 ELFRING FONTS INC.

ASCII CODES WITH GREEK CHARACTERS

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

Representação de Caracteres

CHAPTER 8 BAR CODE CONTROL

Characters & Strings Lesson 1 Outline

Create!form Barcodes. User Guide

An Incomplete C++ Primer. University of Wyoming MA 5310

Comp151. Definitions & Declarations

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Command Emulator STAR Line Mode Command Specifications

Model 200 / 250 / 260 Programming Guide

MK-SERIE 1000/1500/2000 AllOfBarcode.de Michael Krug Traunstein BARCODE SCANNER

Barcode Magstripe. Decoder & Scanner. Programming Manual

C Examples! Jennifer Rexford!

Part No. : MUL PROGRAMMING GUIDE

DL910 SERIES. Instruction Manual

C++ INTERVIEW QUESTIONS

C++ Programming Language

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Talk Encoding Issues. An overview to understand and be able to handle encoding issues in a better way. Susanne Ebrecht

Semantic Checker (Part I)

Teletypewriter Communication Codes

C++FA 5.1 PRACTICE MID-TERM EXAM

TELOCATOR ALPHANUMERIC PROTOCOL (TAP)

Scanner Configuration

The C Programming Language course syllabus associate level

Barcode Scanning Made Easy. Programming Guide

Object Oriented Software Design II

ESPA Nov 1984 PROPOSAL FOR SERIAL DATA INTERFACE FOR PAGING EQUIPMENT CONTENTS 1. INTRODUCTION 2. CHARACTER DESCRIPTION

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Informatica e Sistemi in Tempo Reale

5 Arrays and Pointers

ASCII control characters (character code 0-31)

S302D. Programming Guide. 2D Imaging Barcode Scanner. Advanced Handheld High-Speed Laser Scanner

1 Abstract Data Types Information Hiding

Barcode Scanning Made Easy. WWS500 Programming Guide

How To Write Portable Programs In C

MINIMAG. Magnetic Stripe Reader Keyboard Wedge. User s Manual

Enter/Exit programming

Digital Logic Design. Introduction

C++ Language Tutorial

Member Functions of the istream Class

Object Oriented Software Design II

El Dorado Union High School District Educational Services

Java Interview Questions and Answers

Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

Index...1. Introduction...3. Installation- Keyboard Wedge...3 RS USB...3. Default Setting for each barcode shown as below:...

Security Protection of Software Programs by Information Sharing and Authentication Techniques Using Invisible ASCII Control Codes

7-Bit coded Character Set

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Barcode reader setup manual

C++FA 3.1 OPTIMIZING C++

SQLITE C/C++ TUTORIAL

BRMO 80 / ETH-IP. User Manual. Réf : MU-BRMO 80-ETH-IP-1.4-EN

Chapter 2: Elements of Java


How Compilers Work. by Walter Bright. Digital Mars

Basics of C++ and object orientation in OpenFOAM

C++ Crash Kurs. C++ Object-Oriented Programming

INTERNATIONAL STANDARD

MK D Imager Barcode Scanner Configuration Guide

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Applied Data Communication Lecture 14

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Semantic Analysis: Types and Type Checking

ESC/POS Command Specifications

Dalhousie University CSCI 2132 Software Development Winter 2015 Lab 7, March 11

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Object Oriented Software Design II

Software Engineering Concepts: Testing. Pointers & Dynamic Allocation. CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

HANDHELD LASER SCANNER

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Object-Oriented Programming

Logging. Working with the POCO logging framework.

An API for Reading the MySQL Binary Log

Tutorial on C Language Programming

Note: Syntactically, a ; is needed at the end of a struct definition.

Sources: On the Web: Slides will be available on:

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Transcription:

Login Name _ Signature Name _ Student ID Midterm CSE 131 Fall 2015 Page 1 Page 2 Page 3 Page 4 Page 5 (30 points) (26 points) (24 points) (20 points) (28 points) Subtotal (128 points = 100%) Page 6 Extra Credit (8 points) Total This exam is to be taken by yourself with closed books, closed notes, no electronic devices. You are allowed one side of an 8.5"x11" sheet of paper handwritten by you. 0

1. Given the following CUP grammar snippet (assuming all other Lexing and terminals are correct): Expr ::= Expr {: System.out.println("A"); : T_STAR Des {: System.out.println("B"); : Des ; Des ::= T_STAR {: System.out.println("C"); : Des {: System.out.println("D"); : T_PLUSPLUS {: System.out.println("E"); : Des {: System.out.println("F"); : T_AMPERSAND {: System.out.println("G"); : Des {: System.out.println("H"); : Des2 ; Des2 ::= Des2 {: System.out.println("I"); : T_DOT T_ID {: System.out.println("J"); : Des2 {: System.out.println("K"); : T_PLUSPLUS {: System.out.println("L"); : Des2 {: System.out.println("M"); : T_LBRACKET Expr T_RBRACKET {: System.out.println("N"); : Des3 ; Des3 ::= T_ID {: System.out.println("O"); : ; What is the output when parsing the follow expression (you should have 23 lines/letters in your output): [23pts] Output **a * *b[c*c] * **d In the above grammar, does the multiplication (*) operator have left-to-right or right-to-left associativity? [2pts] _ What type must variables a, b, c, and d be defined for the above expression to be semantically correct and result in a type int? Do not define these variables using arrays. [5pts] _ a; _ b; _ c; _ d; 1

2. Given the following pseudocode, determine the program output based on the specified scoping rule: [26pts] int x = 0; int y = 0; -- global var declaration -- global var declaration int deimos( int dread ) { int y = dread + 10; -- local var declaration if ( dread > 0 ) { x += deimos(dread 1); cout << x << endl; cout << y << endl; return y; int phobos ( int fear ) { int x = fear + 5; -- local var declaration if ( fear > 0 ) { y += phobos(fear 2); cout << x << endl; cout << y << endl; int z = x + y; -- local var declaration return z + deimos(x % 2); cout << phobos(2) << endl; What does the program output if the language uses static scoping? What does the program output if the language uses dynamic scoping? 2

3. Show the memory layout of the following C struct definition taking into consideration the SPARC data type memory alignment restrictions discussed in class. Fill bytes in memory with the appropriate struct member/field name. For example, if member/field name p takes 4 bytes, you will have 4 p's in the appropriate memory locations. If the member/field is an array, use the name followed by the index number. For example, some number of p[0], p[1], p[2], etc. If the member/field is a struct, use the member name followed by its member names (e.g. p.a, p.b, etc.). If the member/field is an array of structs, include both the index and member name (e.g. p[0].a). Place an X in any bytes of padding. Structs/unions are padded so the total size is evenly divisible by the strictest alignment requirement of its members. [14pts figure; 10pts questions] struct sojourner { double h; char i; ; struct pathfinder { char m; struct sojourner a; struct sojourner * r[3]; short k; ; struct pathfinder mars; low memory mars: high memory What is the sizeof( mars )? _ What is the offsetof( struct pathfinder, r[2] )? _ If struct pathfinder had been defined as union, what would be sizeof( union pathfinder )? _ If you rearrange the order of the struct members in struct pathfinder to minimize padding, what would be the size of this modified struct pathfinder? _ How many bytes are saved by rearranging the struct pathfinder members to minimize padding? _ 3

4. Given the following C++ program and taking into consideration how struct constructors and destructors are called as discussed in class, determine the output generated by this program: [16pts] #include <iostream> using namespace std; struct MARK { int id; ; MARK(int id) { this->id = id; cout << "MARK CTOR: " << this->id << endl; ~MARK() { cout << "MARK DTOR: " << this->id << endl; struct MARK Watney1(0); struct MARK * Watney2[4]; int main() { cout << "MAIN: 1" << endl; for ( int i = 0; i < 3; ++i ) { struct MARK Watney3(3); if ( i % 2 ) { struct MARK Watney4(4); Watney2[i] = new struct MARK(20 + i); if ( Watney2[i]!= NULL ) { delete Watney2[i]; struct MARK Watney5(5); cout << "MAIN: 2" << endl; return 0; Output Handling array comparison and assignment in C: In C, one should call the library function _ in order to compare if two arrays of arbitrary data type are equal or not. [2pts] In C, one should call the library function _ in order to assign the contents of one array of arbitrary data type into another array of that same data type and size, where the two arrays may or may not overlap memory addresses. [2pts] 4

5. Given the following C code, indicate which of the 5 main areas of the C Runtime Environment each expression is located in: [14pts] int A = 5; int * B; int * C; void D ( int E ) { int F; static int G = 2; B = &G; return; B = &F; A _ F _ B _ G _ *B _ H _ C _ *H _ *C _ **H _ D _ argc _ int main ( int argc, char *argv[] ) { C = (int *) calloc(1, sizeof(int)); E _ argv _ int ** H = &C; D(360); <------ determine runtime areas at this point in time free(c); C = NULL; return 0; What occurs when a binding lives longer than its object? [2pts] What occurs when an object lives longer than its binding? [2pts] State whether constant folding will be performed on one or more arithmetic expressions in the following statements by the compiler according to this quarter s Reduced-C spec (Y or N): [10pts] function : void main() { const int a = -1; int b = 2; int c = a + a; int d[30]; c = a + 2; c = 1 + 2; d[b + c + 4] = a; d[-5 + (2 / c)]++; d[(-5 + 2) / c]++; d[-a]; d[a * a] = a; d[b] = a ^ a a; 5

Extra Credit What gets printed when the following C program is executed? [8pts] #include <stdio.h> int main() { char a[] = "POTATO"; char *p = a; printf( "%c\n", *p++ = 1[a] - 7 ); printf( "%c\n", p[3] -= 15 ); printf( "%c\n", ((++p)[1] = a[1] - 2) - 1 ); printf( "%c\n", (p[3] -= 43) + 44 ); printf( "%c\n", ( *p-- = a[3] + (a[0] - a[4]) + 2 )? a[3] : a[4] ); printf( "%c\n", *p = p[3] ); printf( "%s\n", a ); return 0; A portion of the C Operator Precedence Table Operator Associativity ++ postfix increment L to R -- postfix decrement [] array element () function call * indirection R to L ++ prefix increment -- prefix decrement & address-of sizeof size of type/object (type) type cast * multiplication L to R / division % modulus + addition L to R - subtraction.. = assignment R to L Hexadecimal - Character 00 NUL 01 SOH 02 STX 03 ETX 04 EOT 05 ENQ 06 ACK 07 BEL 08 BS 09 HT 0A NL 0B VT 0C NP 0D CR 0E SO 0F SI 10 DLE 11 DC1 12 DC2 13 DC3 14 DC4 15 NAK 16 SYN 17 ETB 18 CAN 19 EM 1A SUB 1B ESC 1C FS 1D GS 1E RS 1F US 20 SP 21! 22 " 23 # 24 $ 25 % 26 & 27 28 ( 29 ) 2A * 2B + 2C, 2D - 2E. 2F / 30 0 31 1 32 2 33 3 34 4 35 5 36 6 37 7 38 8 39 9 3A : 3B ; 3C < 3D = 3E > 3F? 40 @ 41 A 42 B 43 C 44 D 45 E 46 F 47 G 48 H 49 I 4A J 4B K 4C L 4D M 4E N 4F O 50 P 51 Q 52 R 53 S 54 T 55 U 56 V 57 W 58 X 59 Y 5A Z 5B [ 5C \ 5D ] 5E ^ 5F _ 60 61 a 62 b 63 c 64 d 65 e 66 f 67 g 68 h 69 i 6A j 6B k 6C l 6D m 6E n 6F o 70 p 71 q 72 r 73 s 74 t 75 u 76 v 77 w 78 x 79 y 7A z 7B { 7C 7D 7E ~ 7F DEL 6

Scratch Paper 7