Computer Systems Principles. C Pointers
|
|
- Dylan Wilcox
- 5 years ago
- Views:
Transcription
1 Computer Systems Principles C Pointers 1
2 Learning Objectives Learn about floating point number Learn about typedef, enum, and union Learn and understand pointers 2
3 FLOATING POINT NUMBER 3
4 IEEE Floating Point Standard
5 IEEE Floating Point Standard sign bit exponent fraction s exp frac
6 IEEE Floating Point Standard sign bit exponent fraction s exp frac (-1) s x 2 E x F 1. Sign bit sdetermines whether number is negative or positive 2. Exponent E weights value by power of two 3. Fractional part Fnormally a fractional value in range [1.0,2.0).
7 IEEE Floating Point Standard sign bit exponent fraction s exp frac (-1) s x 2 E x F 1. Sign bit sdetermines whether number is negative or positive 2. Exponent E weights value by power of two 3. Fractional part Fnormally a fractional value in range [1.0,2.0). Since F always starts with 1, we don t store it
8 IEEE Floating Point Standard float s exp frac 1 k=8 n=23 8
9 IEEE Floating Point Standard float s exp frac 1 k=8 n=23 double s exp frac 1 k=11 n=52 9
10 IEEE Floating Point Standard s exp frac (-1) s x 2 E x F 10
11 IEEE Floating Point Standard s exp frac (-1) s x 2 E x F when exp= 00..0, represent 0 11
12 IEEE Floating Point Standard s exp frac (-1) s x 2 E x F when exp= 00..0, represent 0 when exp= frac=00..0, represent 12
13 IEEE Floating Point Standard s exp frac (-1) s x 2 E x F when exp= 00..0, represent 0 when exp= frac=00..0, represent frac!=00..0, represent NaN or Not a Number 13
14 IEEE Floating Point Standard s exp frac (-1) s x 2 E x F when exp= 00..0, represent 0 when exp= frac=00..0, represent frac!=00..0, represent NaN or Not a Number Otherwise, E = exp-bias bias=2 k-1-1 float: k=8, bias=127 14
15 Encode 72.0f in IEEE floating point standard s exp frac 1 k=8 n=23 (-1) s x 2 E x F Step 1: Write 72.0 in binary scientific notation 72.0 = =
16 Encode 72.0f in IEEE floating point standard s exp frac 1 k=8 n=23 (-1) s x 2 E x F Step 1: Write 72.0 in binary scientific notation 72.0 = = Step 2: compute fractional value: frac=
17 Encode 72.0f in IEEE floating point standard s exp frac 1 k=8 n=23 (-1) s x 2 E x F Step 1: Write 72.0 in binary scientific notation = = Step 2: compute fractional value: frac= Step 3: compute the exponent value: E = exp bias, exp= E+bias= = =
18 Encode 72.0f in IEEE floating point standard s exp frac 1 k=8 n=23 (-1) s x 2 E x F Step 1: Write 72.0 in binary scientific notation 72.0 = = Step 2: compute fractional value: frac= Step 3: compute the exponent value: E = exp bias, exp= E+bias= = 133 =
19 TYPEDEF 19
20 Typedef Using structures is cumbersome Everything related has to include the struct keyword 20
21 Typedef Using structures is cumbersome Everything related has to include the struct keyword C allows you to give a type an alias typedefis a keyword in C Give a meaningful name to an existing type 21
22 TypedefExample Syntax typedef existing-type new-name typedef unsigned char byte; 22
23 TypedefExample 23
24 TypedefExample struct StudentRecord{ char name[25]; int id; char gender; double gpa; }; typedef struct StudentRecord StudentRecord; 24
25 TypedefExample struct StudentRecord{ char name[25]; int id; char gender; double gpa; }; typedef struct StudentRecord StudentRecord; struct StudentRecord s; StudentRecord s; 25
26 TypedefExample typedef struct StudentRecord { char name[25]; int id; char gender; double gpa; } StudentRecord; 26
27 TypedefExample typedef struct StudentRecord { char name[25]; int id; char gender; double gpa; } StudentRecord; 27
28 TypedefExample typedef struct StudentRecord { char name[25]; int id; char gender; double gpa; } StudentRecord; struct StudentRecord record; 28
29 TypedefExample typedef struct StudentRecord { char name[25]; int id; char gender; double gpa; } StudentRecord; struct StudentRecord record; 29
30 TypedefExample typedef struct StudentRecord { char name[25]; int id; char gender; double gpa; } StudentRecord; StudentRecord record; 30
31 ENUMERATION & UNION 31
32 Enumerations in C What are enumerations? A convenient construct for associating names with constant values that have a type. Syntax: enumcolor { RED, GREEN, BLUE }; enumcolor color = RED; 32
33 What is a union? C Unions Like structures, but every field occupies the same region in memory! The largest type in the union defines the total size of that union. Use one member at a time 33
34 C Unions What is a union? Like structures, but every field occupies the same region in memory! The largest type in the union defines the total size of that union. Use one member at a time Example: union value { float f; int i; char s; }; union value v; v.f = 45.7; v.i = 12; v.s = X ; 34
35 Example: #include <stdio.h> union ufloat { float f; unsigned u; }; C Unions int main() { union ufloat u1; u1.f = 72.0f; printf("%x\n", u1.u); } 35
36 iclickerquestion union value { float f; int i; char s; }; struct value { float f; int I; char s; }; The sizes of the union and the struct are (on x64 with gcc): A. union: 12 bytes, struct 12 bytes B. union: 9 bytes, struct 12 bytes C. union: 4 bytes, struct 9 bytes D. union: 5 bytes, struct 12 bytes E. union 4 bytes, struct 12 bytes 36
37 union.cexample Let us compile this example Compilers usually maintain information about variables, this example is the start of a data structure for doing this Note how the different types interpret the bits differently! This example shows how character arrays and integers are interpreted differently! 37
38 C POINTER 38
39 What is a pointer? C Pointers
40 What is a pointer? C Pointers A pointer is like a mailing address, it tells you where something is located.
41 What is a pointer? C Pointers A pointer is like a mailing address, it tells you where something is located. Every object (including simple data types) in Java and C reside in the memory of the machine.
42 What is a pointer? C Pointers A pointer is like a mailing address, it tells you where something is located. Every object (including simple data types) in Java and C reside in the memory of the machine. A pointerto an object is an address telling You where the object is locatedin memory.
43 C Pointers 43
44 C Pointers So why do I care about pointers?
45 C Pointers So why do I care about pointers? In Java, you do not have access to these pointers (or addresses). In Java, you do nothave access to the address of an object. This provides safety!
46 C Pointers So why do I care about pointers? In Java, you do not have access to these pointers (or addresses). In C, you do have access to the address of an object, which allows you to interact with hardware.
47 #include <stdio.h> int main() { int *ptr; int *ptr2; } C Pointers A pointer is denoted by * and has a type. The type is the kind of thing assumed to be at the location the pointer refers to.
48 #include <stdio.h> int main() { int *ptr; int *ptr2; int x = 2; int y = 5; } C Pointers
49 #include <stdio.h> int main() { int *ptr; int *ptr2; int x = 2; int y = 5; ptr = &x; ptr2 = &y; } C Pointers You can assign an address to a pointer using the address of (&) operator.
50 A Visual int x = 2; x 2 int ptr = &x; ptr &x 50
51 A Visual int x = 2; x 2 A pointer can point to itself. int ptr = &x; ptr &x 51
52 #include <stdio.h> int main() { int *ptr; int *ptr2; int x = 2; int y = 5; ptr = &x; ptr2 = &y; } C Pointers So, if ptris a pointer that refers to a value in memory How do we get the value?
53 #include <stdio.h> C Pointers int main() { int *ptr; int *ptr2; int x = 2; int y = 5; ptr = &x; ptr2 = &y; printf( Value : *ptr = %d\n, *ptr); printf( Address: ptr = %d\n, ptr); } You dereference(follow) the pointer! (Note the *!)
54 C Pointers Imagine we have the following declarations int x; int *ptr = &x;
55 C Pointers Imagine we have the following declarations int x; int *ptr = &x; xis located somewhere in memory ptris also located somewhere in memory
56 C Pointers Imagine we have the following declarations int x; int *ptr = &x; xis located somewhere in memory ptris also located somewhere in memory ptr points to the location representing x.
57 Converse operators: *(&a)=a C Pointers Imagine we have the following declarations int x; int *ptr = &x; xis located somewhere in memory ptris also located somewhere in memory ptr points to the location representing x.
58 C Pointers Each box is a byte Memory 58
59 C Pointers Memory Each box is a byte and has a location. Memory is very much like a a giant character array! 59
60 int *ptr C Pointers int x; int *ptr = &x;? x
61 C Pointers int *ptr *ptr = 0;? x
62 C Pointers int *ptr *ptr = 0; 0 x
63 C Pointers int *ptr *ptr = 0; x = 10; 0 x
64 C Pointers int *ptr *ptr = 0; x = 10; 10 x
65 C Pointers int *ptr *ptr = 0; x = 10;? y 10 x
66 C Pointers int *ptr *ptr = 0; x = 10; ptr = &y;? y What does this do? 10 x
67 C Pointers int *ptr *ptr = 0; x = 10; ptr = &y;? y 10 x What does this do? The pointer (ptr) is assigned a different address.
68 C Pointers int *ptr *ptr = 0; x = 10; ptr = &y; *ptr = 4;? y 10 x
69 C Pointers int *ptr *ptr = 0; x = 10; ptr = &y; *ptr = 4; 4 y 10 x
70 C Pointers int *ptr *ptr = 0; x = 10; ptr = &y; *ptr = 4; 4 y Why is ptrfloating off to the side? I thought it was also in memory? 10 x
71 C Pointers Let us look at this a little more carefully int x; int y; int *ptr; x = 1; y = 2; ptr = &x; *ptr = 99; ptr = &y; *ptr = 88; ?? int *ptr int y? int x
72 C Pointers Let us look at this a little more carefully int x; int y; int *ptr; x = 1; y = 2; ptr = &x; *ptr = 99; ptr = &y; *ptr = 88; ?? int *ptr int y? int x
73 C Pointers Let us look at this a little more carefully int x; int y; int *ptr; x = 1; y = 2; ptr = &x; *ptr = 99; ptr = &y; *ptr = 88; ?? int *ptr int y 1 int x
74 C Pointers Let us look at this a little more carefully int x; int y; int *ptr; x = 1; y = 2; ptr = &x; *ptr = 99; ptr = &y; *ptr = 88; ? 2 int *ptr int y 1 int x
75 C Pointers Let us look at this a little more carefully int x; int y; int *ptr; x = 1; y = 2; ptr = &x; *ptr = 99; ptr = &y; *ptr = 88; int *ptr int y 1 int x
76 C Pointers Let us look at this a little more carefully int x; int y; int *ptr; x = 1; y = 2; ptr = &x; *ptr = 99; ptr = &y; *ptr = 88; int *ptr int y 99 int x
77 C Pointers Let us look at this a little more carefully int x; int y; int *ptr; x = 1; y = 2; ptr = &x; *ptr = 99; ptr = &y; *ptr = 88; int *ptr int y 99 int x
78 C Pointers Let us look at this a little more carefully int x; int y; int *ptr; x = 1; y = 2; ptr = &x; *ptr = 99; ptr = &y; *ptr = 88; int *ptr int y 99 int x
79 Let us look at this a little more carefully int x; int y; int *ptr; x = 1; y = 2; ptr = &x; *ptr = 99; ptr = &y; *ptr = 88; C Pointers Is this legal? *ptr=&y int *ptr int y 99 int x
80 Pointer to pointer Let us look at this a little more carefully What if we do this? int **dptr = &ptr; int *ptr int y 99 int x
81 Pointer to pointer Let us look at this a little more carefully What if we do this? int **dptr = &ptr; int *ptr int y 99 int x int **dptr
82 Pointer to pointer Let us look at this a little more carefully What if we do this? int **dptr = &ptr; int *ptr int y 99 int x int **dptr
83 PointerArithmetic 83
84 Pointer Arithmetic Let us look at this a little more carefully What does this mean? ptr = ptr + 1; int *ptr int y 99 int x
85 Pointer Arithmetic Let us look at this a little more carefully What does this mean? ptr = ptr + 1; 1 is scaled int *ptr int y 99 int x
86 Pointer Arithmetic Let us look at this a little more carefully What does this mean? ptr = ptr + 1; int *ptr int y 99 int x
87 Pointer Arithmetic Let us look at this a little more carefully What does this mean? ptr = ptr + 1; int *ptr You can use ptr++ or ++ptr, add/subtract a constant int y 99 int x
88 i-clicker question What is the value of y after executing the following program? { int x, y; } int *p; p = &x; x = 5; *p = 23; y = x+1; A.5 B.23 C.6 D.24
89 i-clicker question What is the value of y after executing the following program? { intx, y, a; } int*p, *q; p = &a; q = &x; x = 5; *p = 23; y = x+1; A.5 B.23 C.6 D.24
90 Pointer operations Referencing: Create a location type *p = &var;
91 Pointer operations Referencing: Create a location type *p = &var; Dereferencing: Access a location intx = *ptr; (read)
92 Pointer to Structures struct point { intx; inty; }; struct point { intx; inty; }; struct point origin, *p; p = &origin; printf("origin is (%d,%d)\n",(*pp).x, pp->x); 92
93 Pointer operations Referencing: Create a location type *p = &var; Dereferencing: Access a location intx = *ptr; (read) x = ptr2->field; (read)
94 Pointer operations Referencing: Create a location type *p = &var; Dereferencing: Access a location intx = *ptr; (read) x = ptr2->field; (read) *ptr= x; (write)
95 Pointer operations Referencing: Create a location type *p = &var; Dereferencing: Access a location intx = *ptr; (read) x = ptr2->field; (read) *ptr= x; (write) ptr2->field = x; (write)
96 Pointer operations Referencing: Create a location type *p = &var; Dereferencing: Access a location int x = *ptr; (read) x = ptr2->field; (read) *ptr= x; (write) ptr2->field = x; (write) Aliasing: Copy a pointer type *pa; pa = pb;
Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14
C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition
More informationStructures, Unions Alignment, Padding, Bit Fields Access, Initialization Compound Literals Opaque Structures Summary. Structures
Structures Proseminar C Grundlagen und Konzepte Michael Kuhn Research Group Scientific Computing Department of Informatics Faculty of Mathematics, Informatics und Natural Sciences University of Hamburg
More informationNumber Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example
Appendix F Number Systems Binary Numbers Decimal notation represents numbers as powers of 10, for example 1729 1 103 7 102 2 101 9 100 decimal = + + + There is no particular reason for the choice of 10,
More informationCOMP2611: Computer Organization. Data Representation
COMP2611: Computer Organization Comp2611 Fall 2015 2 1. Binary numbers and 2 s Complement Numbers 3 Bits: are the basis for binary number representation in digital computers What you will learn here: How
More informationSyntax and Variables
Syntax and Variables What the Compiler needs to understand your program, and managing data 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line
More informationCS2351 Data Structures. Lecture 7: A Brief Review of Pointers in C
CS2351 Data Structures Lecture 7: A Brief Review of Pointers in C 1 About this lecture Pointer is a useful object that allows us to access different places in our memory We will review the basic use of
More informationFirst of all, it is a variable, just like other variables you studied
Pointers: Basics What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the address (rather than the value)
More informationProgramming in C - Part 2
Programming in C - Part 2 CPSC 457 Mohammad Reza Zakerinasab May 11, 2016 These slides are forked from slides created by Mike Clark Where to find these slides and related source code? http://goo.gl/k1qixb
More informationInput And Output of C++
Input And Output of C++ Input And Output of C++ Seperating Lines of Output New lines in output Recall: "\n" "newline" A second method: object endl Examples: cout
More informationRepresenting and Manipulating Floating Points. Jo, Heeseung
Representing and Manipulating Floating Points Jo, Heeseung The Problem How to represent fractional values with finite number of bits? 0.1 0.612 3.14159265358979323846264338327950288... 2 Fractional Binary
More informationDescription Hex M E V smallest value > largest denormalized negative infinity number with hex representation 3BB0 ---
CSE2421 HOMEWORK #2 DUE DATE: MONDAY 11/5 11:59pm PROBLEM 2.84 Given a floating-point format with a k-bit exponent and an n-bit fraction, write formulas for the exponent E, significand M, the fraction
More informationMore about Binary 9/6/2016
More about Binary 9/6/2016 Unsigned vs. Two s Complement 8-bit example: 1 1 0 0 0 0 1 1 2 7 +2 6 + 2 1 +2 0 = 128+64+2+1 = 195-2 7 +2 6 + 2 1 +2 0 = -128+64+2+1 = -61 Why does two s complement work this
More informationCS 61c: Great Ideas in Computer Architecture
Arrays, Strings, and Some More Pointers June 24, 2014 Review of Last Lecture C Basics Variables, functioss, control flow, types, structs Only 0 and NULL evaluate to false Pointers hold addresses Address
More informationSystems Programming and Computer Architecture ( )
(252-0061-00) Session 9 Floating Point Systems Group Department of Computer Science ETH Zürich 1 Floating Point Recap for the Assignment 2 Floating Point Representation Numerical Form Scientific Notation
More informationA Fast Review of C Essentials Part I
A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types
More informationCS Programming In C
CS 24000 - Programming In C Week Two: Basic C Program Organization and Data Types Zhiyuan Li Department of Computer Science Purdue University, USA 2 int main() { } return 0; The Simplest C Program C programs
More informationComputer Systems Programming. Practice Midterm. Name:
Computer Systems Programming Practice Midterm Name: 1. (4 pts) (K&R Ch 1-4) What is the output of the following C code? main() { int i = 6; int j = -35; printf( %d %d\n,i++, ++j); i = i >
More informationSEE2030: Introduction to Computer Systems (Fall 2017) Programming Assignment #2:
SEE2030: Introduction to Computer Systems (Fall 2017) Programming Assignment #2: Implementing Arithmetic Operations using the Tiny FP (8-bit floating point) representation Due: October 15th (Sunday), 11:59PM
More informationBinghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program
Syntax What the Compiler needs to understand your program 1 Pre-Processing Any line that starts with # is a pre-processor directive Pre-processor consumes that entire line Possibly replacing it with other
More informationData Representation and Storage. Some definitions (in C)
Data Representation and Storage Learning Objectives Define the following terms (with respect to C): Object Declaration Definition Alias Fundamental type Derived type Use pointer arithmetic correctly Explain
More informationPointers, Dynamic Data, and Reference Types
Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation The new operator The delete operator Dynamic Memory Allocation for Arrays 1 C++ Data Types simple
More information211: Computer Architecture Summer 2016
211: Computer Architecture Summer 2016 Liu Liu Topic: C Programming Data Representation I/O: - (example) cprintf.c Memory: - memory address - stack / heap / constant space - basic data layout Pointer:
More information(T) x. Casts. A cast converts the value held in variable x to type T
Several New Things 2 s complement representation of negative integers The data size flag in the conversion specification of printf Recast of &n to unsigned long to get the address 2 3 Casts (T) x A cast
More informationRepresenting and Manipulating Floating Points
Representing and Manipulating Floating Points Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu The Problem How to represent fractional values with
More informationProgramming in C++ 6. Floating point data types
Programming in C++ 6. Floating point data types! Introduction! Type double! Type float! Changing types! Type promotion & conversion! Casts! Initialization! Assignment operators! Summary 1 Introduction
More informationPROGRAMMAZIONE I A.A. 2017/2018
PROGRAMMAZIONE I A.A. 2017/2018 A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. DECLARING POINTERS POINTERS A pointer represents both
More informationAgenda. Peer Instruction Question 1. Peer Instruction Answer 1. Peer Instruction Question 2 6/22/2011
CS 61C: Great Ideas in Computer Architecture (Machine Structures) Introduction to C (Part II) Instructors: Randy H. Katz David A. Patterson http://inst.eecs.berkeley.edu/~cs61c/sp11 Spring 2011 -- Lecture
More informationLaboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information
Laboratory 2: Programming Basics and Variables Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information 3. Comment: a. name your program with extension.c b. use o option to specify
More informationMidterm Exam Answers Instructor: Randy Shepherd CSCI-UA.0201 Spring 2017
Section 1: Multiple choice (select any that apply) - 20 points 01. Representing 10 using the 4 byte unsigned integer encoding and using 4 byte two s complements encoding yields the same bit pattern. (a)
More informationSimple Data Types in C. Alan L. Cox
Simple Data Types in C Alan L. Cox alc@rice.edu Objectives Be able to explain to others what a data type is Be able to use basic data types in C programs Be able to see the inaccuracies and limitations
More informationData Representation and Storage
Data Representation and Storage Learning Objectives Define the following terms (with respect to C): Object Declaration Definition Alias Fundamental type Derived type Use size_t, ssize_t appropriately Use
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationCompiling and Running a C Program in Unix
CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 95 ] Compiling and Running a C Program in Unix Simple scenario in which your program is in a single file: Suppose you want to name
More informationIMPORTANT QUESTIONS IN C FOR THE INTERVIEW
IMPORTANT QUESTIONS IN C FOR THE INTERVIEW 1. What is a header file? Header file is a simple text file which contains prototypes of all in-built functions, predefined variables and symbolic constants.
More informationIEEE Standard for Floating-Point Arithmetic: 754
IEEE Standard for Floating-Point Arithmetic: 754 G.E. Antoniou G.E. Antoniou () IEEE Standard for Floating-Point Arithmetic: 754 1 / 34 Floating Point Standard: IEEE 754 1985/2008 Established in 1985 (2008)
More informationCS 261 Fall Floating-Point Numbers. Mike Lam, Professor. https://xkcd.com/217/
CS 261 Fall 2017 Mike Lam, Professor https://xkcd.com/217/ Floating-Point Numbers Floating-point Topics Binary fractions Floating-point representation Conversions and rounding error Binary fractions Now
More informationChapter 3. Fundamental Data Types
Chapter 3. Fundamental Data Types Byoung-Tak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr Variable Declaration
More informationRepresenting and Manipulating Floating Points. Computer Systems Laboratory Sungkyunkwan University
Representing and Manipulating Floating Points Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu The Problem How to represent fractional values with
More informationChapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation
Chapter 2 Float Point Arithmetic Topics IEEE Floating Point Standard Fractional Binary Numbers Rounding Floating Point Operations Mathematical properties Real Numbers in Decimal Notation Representation
More informationCS 61C: Great Ideas in Computer Architecture Introduction to C
CS 61C: Great Ideas in Computer Architecture Introduction to C Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/ 1 Agenda C vs. Java vs. Python Quick Start Introduction
More informationFloating Point Arithmetic
Floating Point Arithmetic Computer Systems, Section 2.4 Abstraction Anything that is not an integer can be thought of as . e.g. 391.1356 Or can be thought of as + /
More informationUnit IV & V Previous Papers 1 mark Answers
1 What is pointer to structure? Pointer to structure: Unit IV & V Previous Papers 1 mark Answers The beginning address of a structure can be accessed through the use of the address (&) operator If a variable
More informationCS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.
CS 265 Computer Architecture Wei Lu, Ph.D., P.Eng. 1 Part 1: Data Representation Our goal: revisit and re-establish fundamental of mathematics for the computer architecture course Overview: what are bits
More informationLecture 2: C Programm
0 3 E CS 1 Lecture 2: C Programm ing C Programming Procedural thought process No built in object abstractions data separate from methods/functions Low memory overhead compared to Java No overhead of classes
More informationDeclaration. Fundamental Data Types. Modifying the Basic Types. Basic Data Types. All variables must be declared before being used.
Declaration Fundamental Data Types All variables must be declared before being used. Tells compiler to set aside an appropriate amount of space in memory to hold a value. Enables the compiler to perform
More informationOperating Systems 2INC0 C course Pointer Advanced. Dr. Ir. Ion Barosan
Operating Systems 2INC0 C course Pointer Advanced Dr. Ir. Ion Barosan (i.barosan@tue.nl) Containt Pointers Definition and Initilization Ponter Operators Pointer Arithmetic and Array Calling Functions by
More informationCS 261 Fall Floating-Point Numbers. Mike Lam, Professor.
CS 261 Fall 2018 Mike Lam, Professor https://xkcd.com/217/ Floating-Point Numbers Floating-point Topics Binary fractions Floating-point representation Conversions and rounding error Binary fractions Now
More informationWeek 3 Lecture 2. Types Constants and Variables
Lecture 2 Types Constants and Variables Types Computers store bits: strings of 0s and 1s Types define how bits are interpreted They can be integers (whole numbers): 1, 2, 3 They can be characters 'a',
More informationPOINTER & REFERENCE VARIABLES
Lecture 9 POINTER & REFERENCE VARIABLES Declaring data pointer variables Assignment operations with pointers Referring objects using pointer variables Generic pointers Operations with pointer variables
More informationComputer System and programming in C
1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign
More informationLanguage comparison. C has pointers. Java has references. C++ has pointers and references
Pointers CSE 2451 Language comparison C has pointers Java has references C++ has pointers and references Pointers Values of variables are stored in memory, at a particular location A location is identified
More informationCSE 220: Systems Programming
CSE 220: Systems Programming Pointers and Data Representation Ethan Blanton Department of Computer Science and Engineering University at Buffalo More on void Pointers Void pointers are powerful for raw
More informationCOMP 2355 Introduction to Systems Programming
COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Functions Similar to (static) methods in Java without the class: int f(int a, int
More informationComputer Organization: A Programmer's Perspective
A Programmer's Perspective Representing Numbers Gal A. Kaminka galk@cs.biu.ac.il Fractional Binary Numbers 2 i 2 i 1 4 2 1 b i b i 1 b 2 b 1 b 0. b 1 b 2 b 3 b j 1/2 1/4 1/8 Representation Bits to right
More informationIV Unit Second Part STRUCTURES
STRUCTURES IV Unit Second Part Structure is a very useful derived data type supported in c that allows grouping one or more variables of different data types with a single name. The general syntax of structure
More informationFundamentals of Programming. Lecture 12: C Structures, Unions, Bit Manipulations and Enumerations
Fundamentals of Programming Lecture 12: C Structures, Unions, Bit Manipulations and Enumerations Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department
More informationFloating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.
Floating-point Arithmetic Reading: pp. 312-328 Floating-Point Representation Non-scientific floating point numbers: A non-integer can be represented as: 2 4 2 3 2 2 2 1 2 0.2-1 2-2 2-3 2-4 where you sum
More informationCSCI 402: Computer Architectures. Arithmetic for Computers (3) Fengguang Song Department of Computer & Information Science IUPUI.
CSCI 402: Computer Architectures Arithmetic for Computers (3) Fengguang Song Department of Computer & Information Science IUPUI 3.5 Today s Contents Floating point numbers: 2.5, 10.1, 100.2, etc.. How
More informationRepresenting and Manipulating Floating Points
Representing and Manipulating Floating Points Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu The Problem How to represent fractional values with
More informationCS107 Handout 13 Spring 2008 April 18, 2008 Computer Architecture: Take II
CS107 Handout 13 Spring 2008 April 18, 2008 Computer Architecture: Take II Example: Simple variables Handout written by Julie Zelenski and Nick Parlante A variable is a location in memory. When a variable
More informationLab 3. Pointers Programming Lab (Using C) XU Silei
Lab 3. Pointers Programming Lab (Using C) XU Silei slxu@cse.cuhk.edu.hk Outline What is Pointer Memory Address & Pointers How to use Pointers Pointers Assignments Call-by-Value & Call-by-Address Functions
More informationPointers. Memory. void foo() { }//return
Pointers Pointers Every location in memory has a unique number assigned to it called it s address A pointer is a variable that holds a memory address A pointer can be used to store an object or variable
More informationFloating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !
Floating point Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties Next time! The machine model Chris Riesbeck, Fall 2011 Checkpoint IEEE Floating point Floating
More informationFloating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3
Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Instructor: Nicole Hynes nicole.hynes@rutgers.edu 1 Fixed Point Numbers Fixed point number: integer part
More informationTopics Introduction to Microprocessors
Topics 22440 Introduction to Microprocessors C-Language Review (I) Important: : You will not learn how to code in C in this one lecture! You ll still need some sort of C reference. C Syntax Important Tidits
More informationFloating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754
Floating Point Puzzles Topics Lecture 3B Floating Point IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties For each of the following C expressions, either: Argue that
More informationVariation of Pointers
Variation of Pointers A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before
More informationCS 33. Data Representation (Part 3) CS33 Intro to Computer Systems VIII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.
CS 33 Data Representation (Part 3) CS33 Intro to Computer Systems VIII 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. Byte-Oriented Memory Organization 00 0 FF F Programs refer to data by address
More informationCPSC 3740 Programming Languages University of Lethbridge. Data Types
Data Types A data type defines a collection of data values and a set of predefined operations on those values Some languages allow user to define additional types Useful for error detection through type
More informationTYPES, VALUES AND DECLARATIONS
COSC 2P90 TYPES, VALUES AND DECLARATIONS (c) S. Thompson, M. Winters 1 Names, References, Values & Types data items have a value and a type type determines set of operations variables Have an identifier
More informationCMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 13, SPRING 2013
CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 13, SPRING 2013 TOPICS TODAY Reminder: MIDTERM EXAM on THURSDAY Pointer Basics Pointers & Arrays Pointers & Strings Pointers & Structs
More informationby: Lizawati, Norhidayah & Muhammad Noorazlan Shah Computer Engineering, FKEKK, UTeM
by: Lizawati, Norhidayah & Muhammad Noorazlan Shah Computer Engineering, FKEKK, UTeM At the end of this chapter, the students should be able to: understand and apply typedef understand and apply structure
More informationC Language, Token, Keywords, Constant, variable
C Language, Token, Keywords, Constant, variable A language written by Brian Kernighan and Dennis Ritchie. This was to be the language that UNIX was written in to become the first "portable" language. C
More informationC Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,
More informationC: Pointers. C: Pointers. Department of Computer Science College of Engineering Boise State University. September 11, /21
Department of Computer Science College of Engineering Boise State University September 11, 2017 1/21 Pointers A pointer is a variable that stores the address of another variable. Pointers are similar to
More informationIntro to C: Pointers and Arrays
Lecture 4 Computer Science 61C Spring 2017 January 25th, 2017 Intro to C: Pointers and Arrays 1 Administrivia Teaching Assistants: Let s try that again. Lectures are recorded. Waitlist/Concurrent Enrollment
More informationECE 250 / CS 250 Computer Architecture. C to Binary: Memory & Data Representations. Benjamin Lee
ECE 250 / CS 250 Computer Architecture C to Binary: Memory & Data Representations Benjamin Lee Slides based on those from Alvin Lebeck, Daniel Sorin, Andrew Hilton, Amir Roth, Gershon Kedem Administrivia
More informationFundamentals of Programming
Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables
More informationDarshan Institute of Engineering & Technology for Diploma Studies Unit 5
1 What is structure? How to declare a Structure? Explain with Example Structure is a collection of logically related data items of different data types grouped together under a single name. Structure is
More informationFeatures of C. Portable Procedural / Modular Structured Language Statically typed Middle level language
1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC
More informationCS 61C: Great Ideas in Computer Architecture C Pointers. Instructors: Vladimir Stojanovic & Nicholas Weaver
CS 61C: Great Ideas in Computer Architecture C Pointers Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/sp16 1 Agenda Pointers Arrays in C 2 Address vs. Value Consider
More informationWork relative to other classes
Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language
More informationVariables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park
Variables in C CMSC 104, Fall 2012 John Y. Park 1 Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement 2 What Are Variables in C? Variables in C have the
More informationRepresenting and Manipulating Floating Points
Representing and Manipulating Floating Points Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu SSE23: Introduction to Computer Systems, Spring 218,
More informationFloating Point Numbers
Floating Point Numbers Computer Systems Organization (Spring 2016) CSCI-UA 201, Section 2 Instructor: Joanna Klukowska Slides adapted from Randal E. Bryant and David R. O Hallaron (CMU) Mohamed Zahran
More informationFloating Point Numbers
Floating Point Numbers Computer Systems Organization (Spring 2016) CSCI-UA 201, Section 2 Fractions in Binary Instructor: Joanna Klukowska Slides adapted from Randal E. Bryant and David R. O Hallaron (CMU)
More information3/22/2016. Pointer Basics. What is a pointer? C Language III. CMSC 313 Sections 01, 02. pointer = memory address + type
Pointer Basics What is a pointer? pointer = memory address + type C Language III CMSC 313 Sections 01, 02 A pointer can contain the memory address of any variable type A primitive (int, char, float) An
More information[0569] p 0318 garbage
A Pointer is a variable which contains the address of another variable. Declaration syntax: Pointer_type *pointer_name; This declaration will create a pointer of the pointer_name which will point to the
More informationC Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017
C Concepts - I/O Lecture 19 COP 3014 Fall 2017 November 29, 2017 C vs. C++: Some important differences C has been around since around 1970 (or before) C++ was based on the C language While C is not actually
More informationIntroduction to C. Why C? Difference between Python and C C compiler stages Basic syntax in C
Final Review CS304 Introduction to C Why C? Difference between Python and C C compiler stages Basic syntax in C Pointers What is a pointer? declaration, &, dereference... Pointer & dynamic memory allocation
More informationProgramming and Data Structures
Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()
More information10/20/2015. Midterm Topic Review. Pointer Basics. C Language III. CMSC 313 Sections 01, 02. Adapted from Richard Chang, CMSC 313 Spring 2013
Midterm Topic Review Pointer Basics C Language III CMSC 313 Sections 01, 02 1 What is a pointer? Why Pointers? Pointer Caution pointer = memory address + type A pointer can contain the memory address of
More informationData Type Fall 2014 Jinkyu Jeong
Data Type Fall 2014 Jinkyu Jeong (jinkyu@skku.edu) 1 Syntax Rules Recap. keywords break double if sizeof void case else int static... Identifiers not#me scanf 123th printf _id so_am_i gedd007 Constants
More informationCSE 230 Intermediate Programming in C and C++
CSE 230 Intermediate Programming in C and C++ Unions and Bit Fields Fall 2017 Stony Brook University Instructor: Shebuti Rayana http://www3.cs.stonybrook.edu/~cse230/ Union Like structures, unions are
More informationIntegers and Floating Point
CMPE12 More about Numbers Integers and Floating Point (Rest of Textbook Chapter 2 plus more)" Review: Unsigned Integer A string of 0s and 1s that represent a positive integer." String is X n-1, X n-2,
More informationMain Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University
C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types
More information12 CREATING NEW TYPES
Lecture 12 CREATING NEW TYPES of DATA Typedef declaration Enumeration Structure Bit fields Uninon Creating New Types Is difficult to solve complex problems by using programs written with only fundamental
More informationMotivation was to facilitate development of systems software, especially OS development.
A History Lesson C Basics 1 Development of language by Dennis Ritchie at Bell Labs culminated in the C language in 1972. Motivation was to facilitate development of systems software, especially OS development.
More informationBits, Words, and Integers
Computer Science 52 Bits, Words, and Integers Spring Semester, 2017 In this document, we look at how bits are organized into meaningful data. In particular, we will see the details of how integers are
More informationCS 61C: Great Ideas in Computer Architecture. C Arrays, Strings, More Pointers
CS 61C: Great Ideas in Computer Architecture C Arrays, Strings, More Pointers Instructor: Justin Hsia 6/20/2012 Summer 2012 Lecture #3 1 Review of Last Lecture C Basics Variables, Functions, Flow Control,
More information