CSE 12 Spring 2016 Week One, Lecture Two

Similar documents
CSE 12 Spring 2018 Week One, Lecture Two

211: Computer Architecture Summer 2016

Input / Output Functions

File IO and command line input CSE 2451

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

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

System Software Experiment 1 Lecture 7

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

Standard C Library Functions

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

Under the Hood: Data Representations, Memory and Bit Operations. Computer Science 104 Lecture 3

Lecture 03 Bits, Bytes and Data Types

C programming basics T3-1 -

PROGRAMMAZIONE I A.A. 2017/2018

CSE 12 Week Three Lecture One Tomorrow s discussion: Getting started on hw4

SWEN-250 Personal SE. Introduction to C

CS246 Spring14 Programming Paradigm Files, Pipes and Redirection

C: Arrays, and strings. Department of Computer Science College of Engineering Boise State University. September 11, /16

C mini reference. 5 Binary numbers 12

Goals of C "" The Goals of C (cont.) "" Goals of this Lecture"" The Design of C: A Rational Reconstruction"

Representation of Information

CA341 - Comparative Programming Languages

CSC 1600 Memory Layout for Unix Processes"

Content. Input Output Devices File access Function of File I/O Redirection Command-line arguments

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

CSci 4061 Introduction to Operating Systems. Input/Output: High-level

Today s Learning Objectives

Day14 A. Young W. Lim Tue. Young W. Lim Day14 A Tue 1 / 15

ECE551 Midterm Version 1

TI2725-C, C programming lab, course

LING 388: Computers and Language. Lecture 5

CS240: Programming in C

CSE 303: Concepts and Tools for Software Development

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

Programming refresher and intro to C programming

Wawrzynek & Weaver CS 61C. Sp 2018 Great Ideas in Computer Architecture MT 1. Print your name:,

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

Continued from previous lecture

Presented By : Gaurav Juneja

Lecture 14. No in-class files today. Homework 7 (due on Wednesday) and Project 3 (due in 10 days) posted. Questions?

Final CSE 131B Spring 2004

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

Binary Values. CSE 410 Lecture 02

PRINCIPLES OF OPERATING SYSTEMS

The C++ Language. Arizona State University 1

Pointers cause EVERYBODY problems at some time or another. char x[10] or char y[8][10] or char z[9][9][9] etc.

Systems Programming. 08. Standard I/O Library. Alexander Holupirek

Standard I/O in C and C++

Wawrzynek & Weaver CS 61C. Sp 2018 Great Ideas in Computer Architecture MT 1. Print your name:,

In the case of the dynamic array, the space must be deallocated when the program is finished with it. free(x);

Memory Layout, File I/O. Bryce Boe 2013/06/27 CS24, Summer 2013 C

Text Output and Input; Redirection

UNIT 7A Data Representation: Numbers and Text. Digital Data

Inf2C - Computer Systems Lecture 2 Data Representation

Programming in C. Session 8. Seema Sirpal Delhi University Computer Centre

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Contents. A Review of C language. Visual C Visual C++ 6.0

Quick review of previous lecture Ch6 Structure Ch7 I/O. EECS2031 Software Tools. C - Structures, Unions, Enums & Typedef (K&R Ch.

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

CS113: Lecture 7. Topics: The C Preprocessor. I/O, Streams, Files

Time: 8:30-10:00 pm (Arrive at 8:15 pm) Location What to bring:

Work relative to other classes

Lecture 7: file I/O, more Unix

CSE 410: Systems Programming

CS Programming In C

Arrays, Strings, & Pointers

UNIT IV-2. The I/O library functions can be classified into two broad categories:

Course organization. Course introduction ( Week 1)

Topic 8: I/O. Reading: Chapter 7 in Kernighan & Ritchie more details in Appendix B (optional) even more details in GNU C Library manual (optional)

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

Fundamentals of Programming

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING

Chapter 2: Basic Elements of C++

CS 61C: Great Ideas in Computer Architecture. Lecture 3: Pointers. Bernhard Boser & Randy Katz

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Day14 A. Young W. Lim Thr. Young W. Lim Day14 A Thr 1 / 14

UNIX input and output

Fundamental of Programming (C)

CS 61C: Great Ideas in Computer Architecture C Pointers. Instructors: Vladimir Stojanovic & Nicholas Weaver

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Intermediate Programming, Spring 2017*

unsigned char memory[] STACK ¼ 0x xC of address space globals function KERNEL code local variables

The Design of C: A Rational Reconstruction (cont.)

Result: original lp in main is. Goal was.

Programming & Data Structure

C Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017

Introduction to Computing Lecture 03: Basic input / output operations

Inheritance: Develop solutions by abstracting real-world object and their interaction into code to develop software solutions. Layering: Organization

CS & IT Conversions. Magnitude 10,000 1,

Kurt Schmidt. October 30, 2018

Programming Abstractions

CS61, Fall 2012 Section 2 Notes

Java Basic Datatypees

Intro to C: Pointers and Arrays

Binary Representations and Arithmetic

Dynamic memory allocation (malloc)

High-performance computing and programming Intro to C on Unix/Linux. Uppsala universitet

The Design of C: A Rational Reconstruction: Part 2

Agenda. Components of a Computer. Computer Memory Type Name Addr Value. Pointer Type. Pointers. CS 61C: Great Ideas in Computer Architecture

Number Review. Lecture #3 More C intro, C Strings, Arrays, & Malloc Variables. Clarification about counting down

Transcription:

CSE 12 Spring 2016 Week One, Lecture Two Homework One and Two: hw2: Discuss in section today - Introduction to C - Review of basic programming principles - Building from fgetc and fputc - Input and output strings and numbers - Introduction to pointers - Emphasize limits (arrays bounds) Hello World: //Java: public class Driver { public static void main (String [] args) { C++: #include <iostream> using namespace std; int main (int argc, char * const * argv) { C: #include <stdio.h> int main (int argc, char * const * argv) {

Standard output: The regular display output by your program. Java: C++: C: Display is : displayed immediately to the user. Certain events must happen for the display to show: 1. 2. 3. 4. 5. When is display to standard output lost: Ex: When is the following output lost: fprintf (stdout, Hello World ); Ans: 1. 2. 3.

Standard error: The display for Java: C++: C: Display is : displayed immediately to the user When is display to standard output lost: Ex: When is the following output lost: fprintf (stderr, Hello World ); Ans: 1. Standard input: The normal input from for applications. Java: C++: C: Buffered input: (2 buffers: 1 keyboard buffer, 2 standard input buffer) Keyboard buffer: processes all input (backspaces finish keyboard input: \n ) Certain event must happen for the input to get into the standard input buffer: 1. Ex: A - A goes in the buffer, standard input is B - B goes in the buffer, standard input is C - C goes in the buffer, standard input is <ret> - goes into the buffer, keyboard buffer is. How to get input in C: char character = NULL; while (character!= \n ) { character = fgetc (stdin); // <ret>

Standard input is when program begins therefore, a call to fgetc when stdin is empty caused your program to:. Once standard input has contents, then fgetc will and it will return. Exception: Control D input 1) It s the input to end all test cases in the autograder. 2) Your execution score will be 0 if you fail to handle ^D. 3) It s the indication that you are done with your application. 4) To enter End of File also known as EOF. 5) Side note: ^D is in UNIX what ^Z is on Windows. (Do not ^Z on UNIX). Works only when stdin is Input is: ^D Not: 123^D 123^D<ret> ^D<ret>

Numbering Systems: (Why: ) Decimal Hexadecimal Octal Binary Base Base Base Base prefix needed prefix required prefix required Not representable Digits: Digits: Digits: Digits:

Example: Hexadecimal: Mapping of binary easy way to 32 bits = 1 word (size of int, long (C/C++) reading direct contents of memory. Largest Number in 32 bits: - Most significant bit (left most bit: 0 = positive, 1 = negative) Largest Number in 32 bits: - unsigned number: all bits are no bit The Apple Analogy: 1 distinct plate of 10 decimal apples another distinct plate of 012 octal apples another distinct plate of 1010 binary apples another distinct plate of 0xa hexadecimal apples Put them all in one bag how many do you have? Answer: apples! ASCII Codes: American Standard Codes for Information Interchange - displayed to the user - input from the keyboard Example keyboard input: 123\n Example string in C/C++ 123\n NULL = \0 = 0 = 0x0 = the last character in every. Newline = \n = 10 = 0xa = the last character.

Numeric input: C: unsigned long ul; // always positive, 32 bits of magnitude signed long sl; // 1 sign bit, 31 bits of magnitude The computer represents negative numbers in a notation called: Two s complement Two s complement is both an algorithm and a representation - How: o Binary number: flip all bits o Add one Ex: 1 in decimal is 0000000000.000001 in 32 bits in binary How do you represent -1 in two s complement? Here s how: 00000000..00000001: start with a positive number 11111111..11111110: flip +1: add one_ ----------------------------- Ans: Ex: Given an unknown negative number, what it its magnitude? 11111111..11111111: -??? 00000000..00000000: flip +1: add one ------------------------------

Therefore: going positive to negative, negative to positive is the. 111111111 11111111: -1 + 000000000 00000001: +1 ----------------------------- Observation:. Is this a problem? Ans:. Ex in 4 bits, signed addition: 1 bit of sign, 3 bits of magnitude 0101: 5 + 0110: +6 ------- -- Problem: Overflow a bit of magnitude or. 0100: flip + 1: add one ------- Observation: overflow occurred: o o o When a computer program produces overflow what happens? Ans: Ramifications:.

Layout of memory: (You need to know where are the variables that you use, how long they exist, what other variables are nearby). Text: Where your program resides while it is executing. - Function/methods definitions, while loops, if statements, constant strings - Read only Data: - global memory, static variables - created when your program is loaded into memory - go away when your program ends - 0 initialized Stack: (Run-Time Stack RTS) - local variables, parameters, return results (user controlled) - old registers (whatever that is) (by the operating system) - return addresses (whatever that is) (by the operating system) - created when your function/method is called - go away when your function/method ends - uninitialized initialized with contents from the last use of space Heap: - dynamic memory (memory allocated at run-time) - C: malloc (m:memory, alloc: allocate), free frees up the memory - C++: new creates, delete frees up the memory - Java: new creates, garbage collector frees up the memory - C/C++ if you don t free your memory memory leak bad thing!