Midterm CSE 131B Spring 2005

Similar documents
Final CSE 131B Spring 2004

Final CSE 131B Spring 2005

Final CSE 131B Winter 2003

Midterm CSE 131 Winter 2012

Midterm CSE 131 Winter 2014

Midterm CSE 131B Spring 2006

Midterm CSE 131 Winter 2013

Midterm CSE 131 Fall 2014

Final CSE 131 Fall 2014

Midterm CSE 131 Winter 2015

Final CSE 131 Winter 2010

CSE 431S Type Checking. Washington University Spring 2013

Final CSE 131 Winter 2012

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

Francesco Nidito. Programmazione Avanzata AA 2007/08

Homework #3 CS2255 Fall 2012

Final CSE 131 Fall 2015

CSE 30 Fall 2013 Final Exam

CSE 30 Winter 2014 Final Exam

Data Representation and Storage. Some definitions (in C)

CSE 30 Spring 2006 Final Exam

CSE 30 Spring 2007 Final Exam

CSE 30 Fall 2012 Final Exam

CSE 5A Final Fall 2006

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Data Types (cont.) Administrative Issues. Academic Dishonesty. How do we detect plagiarism? Strongly Typed Languages. Type System

CSE 30 Fall 2007 Final Exam

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Structs and Alignment CSE 351 Spring

QUIZ. What are 3 differences between C and C++ const variables?

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

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

Tokens, Expressions and Control Structures

Note 3. Types. Yunheung Paek. Associate Professor Software Optimizations and Restructuring Lab. Seoul National University

Lecture 8: Pointer Arithmetic (review) Endianness Functions and pointers

Type Checking. Prof. James L. Frankel Harvard University

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

CSE 30 Fall 2006 Final Exam

CSE 30 Winter 2009 Final Exam

A Fast Review of C Essentials Part I

COMP-520 GoLite Tutorial

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

BLM2031 Structured Programming. Zeyneb KURT

Lecture 12: Data Types (and Some Leftover ML)

CS107 Handout 13 Spring 2008 April 18, 2008 Computer Architecture: Take II

FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):

QUIZ. What is wrong with this code that uses default arguments?

Types. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus

Program Flow. Instructions and Memory. Why are these 16 bits? C code. Memory. a = b + c. Machine Code. Memory. Assembly Code.

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

Data Representation and Storage

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

Introduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C

Short Notes of CS201

C-LANGUAGE CURRICULAM

Type Bindings. Static Type Binding

Heap Arrays. Steven R. Bagley

Structures, Unions Alignment, Padding, Bit Fields Access, Initialization Compound Literals Opaque Structures Summary. Structures

CSE351 Spring 2018, Final Exam June 6, 2018

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

CS201 - Introduction to Programming Glossary By

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

More about BOOLEAN issues

Inheritance, Polymorphism and the Object Memory Model

Introduction to Programming Using Java (98-388)

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

First of all, it is a variable, just like other variables you studied

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

CSE450. Translation of Programming Languages. Lecture 11: Semantic Analysis: Types & Type Checking

Data Storage. August 9, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 August 9, / 19

Type Conversion. and. Statements

CS3157: Advanced Programming. Announcement

Chapter-8 DATA TYPES. Introduction. Variable:

IMPORTANT QUESTIONS IN C FOR THE INTERVIEW

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

CS 61c: Great Ideas in Computer Architecture

Java Primer 1: Types, Classes and Operators

CS 415 Midterm Exam Spring 2002

EL6483: Brief Overview of C Programming Language

Online Judge and C. Roy Chan. January 12, Outline Information Online Judge Introduction to C. CSC2100B Data Structures Tutorial 1

2. C99 standard guarantees uniqueness of characters for internal names. A. 12 B. 26 C. 31 D. 48

Pointers and Arrays 1

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

C Praktikum. Advanced Pointers. Eugen Betke, Nathanael Hübbe, Michael Kuhn, Jakob Lüttgau, Jannek Squar

Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

1.3b Type Conversion

Procedure and Object- Oriented Abstraction

PIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Stream Computing using Brook+

CS201 Latest Solved MCQs

Fundamentals of Programming Languages

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Lecture 5: Outline. I. Multi- dimensional arrays II. Multi- level arrays III. Structures IV. Data alignment V. Linked Lists

CSI33 Data Structures

CSE 333 Lecture 2 Memory

CS201- Introduction to Programming Current Quizzes

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

C++ ARRAYS POINTERS POINTER ARITHMETIC. Problem Solving with Computers-I

Transcription:

Signature Login Name _ Name Student ID Midterm CSE 131B Spring 2005 Page 1 Page 2 Page 3 Page 4 Page 5 (20 points) (18 points) (22 points) (20 points) (20 points) Subtotal Page 6 Extra Credit (100 points) (5 points) Total 0

1. Consider the following psuedocode: x : string; -- global x procedure set_x ( n : string ) x := n; procedure print_x() output( x ); -- print the value of x procedure one() x : string; set_x( "RED" ); procedure two() set_x( "GREEN" ); -- main starts here set_x( "BLUE" ); one(); two(); What does the program output if the language uses static scoping? (4 points) What does the program output if the language uses dynamic scoping? (4 points) Give an example of a converting type cast/conversion (underlying bit pattern needs to be/is changed). (4 points) Give an example of an implicit type coercion (type conversion without an explicit cast). (4 points) Give an example of a non-converting type cast/conversion (underlying bit pattern does not change). (4 points) 1

2. Given the array declaration C int a[2][3]; Oberon-like VAR a : ARRAY 2,3 OF INTEGER; Mark with an A the memory location(s) where we would find a: a[1][1] a[1,1] low memory high memory Each box represents a byte in memory. (4 points) Show the SPARC memory layout of the following struct/record definition taking into consideration the SPARC data type memory alignment restrictions discussed in class. Fill bytes in memory with the appropriate struct/record 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 p0's, p1's, p2's, etc. Place an X in any bytes of padding. Structs and unions are padded so the total size is evenly divisible by the most strict alignment requirement of its members. (8 points) struct foo { short a; int b; char c[5]; double d; float e; } struct foo fubar; fubar: low memory high memory What is the offsetof( struct foo, d )? _ (2 point) What is the sizeof( struct foo )? _ (2 point) If struct foo had been defined as union foo instead, what would be the sizeof( union foo )? _ (2 points) 2

3. Write a valid Oberon program to perform a simple test of the Project I POINTER type and NEW construct. Declare a global integer pointer named ptr, use NEW with this pointer appropriately, then assign the value 777 to the newly created integer. (11 points) The types in Oberon variable declarations are often unnecessary in the sense that it is possible to infer variables' types and detect type errors simply from their use. However, adding type declarations can change the meanings of certain programs, or make them illegal. Consider the following program fragment: (11 points) IF x1 = x2 THEN x3 := x4 DIV 7 + x1; END; Assume all variables have type INTEGER, REAL, or BOOLEAN. Specify a valid type for each variable so that the code fragment above is legal (no error). x1 x2 x3 x4 Now given the following declaration: VAR x1: REAL; State the (possibly new) type of each the following variables so that the code fragment above is legal (no error). x2 x3 x4 What error, if any, would result if x2 were defined to be of type BOOLEAN instead of what you just specified? What error, if any, would result if x4 were defined to be of type REAL instead of what you just specified? 3

4. Consider the following Oberon code: VAR i : INTEGER; VAR b : BOOLEAN; VAR r : REAL; VAR a : ARRAY 10 OF INTEGER; Example 1: BEGIN a[10] := a[5 + r]; END. Describe all the errors (if any) in the above statement in general terms. State "None" if there are no errors. Example 2: BEGIN IF r < 5.5 THEN r := i; EXIT; END; END. Describe all the errors (if any) in the above statement in general terms. State "None" if there are no errors. With regard to our Nano-Oberon specification, Can a variable of type record be passed by value (non-var) to a procedure? Can a variable of type record be passed by reference (VAR) to a procedure? Can a variable of type array be passed by value (non-var) to a procedure? Can a variable of type array be passed by reference (VAR) to a procedure? Can a variable of type boolean be passed by value (non-var) to a procedure? Can a variable of type boolean be passed by reference (VAR) to a procedure? With regard to this C/C++ array: double arr[5]; What is the sizeof( arr )? If &arr[0] is 8000, what is &arr[3]? What type is &arr[2]? What type is *&arr[2]? 4

5. Describe what each part of the C compilation program execution process does/is responsible for: Assembler... Loader... C Preprocessor... Linkage Editor... C Compiler... Fill in the names of the 5 areas of the C Runtime Environment as laid out by most Unix operating systems (and Solaris on SPARC architecture in particular) as discussed in class. Then state what parts of a C program are in each area. (10 points) low memory high memory 5

Extra Credit (5 points) What is the value of each of the following expressions? char a[] = "This 1 Blows ME Away!"; char *ptr = a; ++*(a + 18) 5[ptr] + 2 ++*a *(&ptr[14]-7) ptr[strlen(ptr)-7] 6