Department of Electronic & Electrical Engineering Types and Memory Addresses Pointers & and * operators.

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 1.
Advertisements

Incomplete Structs struct B; struct A { struct B * partner; // other declarations… }; struct B { struct A * partner; // other declarations… };
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
A pointer is the memory address of a variable. A memory address is a physical location within a system’s memory space. A pointer variable is variable used.
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Pointers.
Unions The storage referenced by a union variable can hold data of different types subject to the restriction that at any one time, the storage holds data.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
Pointers & Dynamic Memory Allocation Mugurel Ionu Andreica Spring 2012.
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
Pointers Discussion 5 Section Housekeeping HW 1 Issues Array Issues Exam 1 Questions? Submitting on Time!
Dynamic Memory Allocation in C++. Memory Segments in C++ Memory is divided in certain segments – Code Segment Stores application code – Data Segment Holds.
1 The first step in understanding pointers is visualizing what they represent at the machine level. In most modern computers, main memory is divided into.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common.
Overview Working directly with memory locations is beneficial. In C, pointers allow you to: change values passed as arguments to functions work directly.
Pointers CSE 2451 Rong Shi.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
Variables and Data Types
Lecture 2 Introduction to Computer Programming CUIT A.M. Gamundani Presentation Layout Data types.
7. Pointers, Dynamic Memory 20 th September IIT Kanpur 1C Course, Programming club, Fall 2008.
GUIDED BY- A.S.MODI MADE BY- 1. SHWETA ALWANI 2. PRIYANKA.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
Info stored in computer (memory) Numbers All in binaray – can be converted to octal, hex Characters ASCII – 1-byte/char Unicode – 2-byte/char Unicode-table.com/en.
C Programming Lecture 16 Pointers. Pointers b A pointer is simply a variable that, like other variables, provides a name for a location (address) in memory.
+ Pointers. + Content Address of operator (&) Pointers Pointers and array.
Computer And Programming Array and Pointer. Array provides a means to allocating and accessing memory. Pointers, on the other hand, provides a way to.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
Pointers PART - 2. Pointers Pointers are variables that contain memory addresses as their values. A variable name directly references a value. A pointer.
Department of Electronic & Electrical Engineering IO reading and writing variables scanf printf format strings "%d %c %f"
Data Types Always data types will decide which type of information we are storing into variables In C programming language we are having 3 types of basic.
 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers.
Pointers 1. Introduction Declaring pointer variables Pointer operators Pointer arithmetic 2 Topics to be Covered.
ADVANCED POINTERS. Overview Review on pointers and arrays Common troubles with pointers Multidimensional arrays Pointers as function arguments Functions.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
Department of Electronic & Electrical Engineering Lecture 3 IO reading and writing variables scanf printf format strings "%d %c %f" Expressions operators.
FUNCTIONS (CONT). Midterm questions (21-30) 21. The underscore can be used anywhere in an identifier. 22. The keyword void is a data type in C. 23. Floating.
Pointers. Introduction to pointers Pointer variables contain memory addresses as their values. Usually, a variable directly contains a specific value.
Pointers as arrays C++ Programming Technologies. Pointers vs. Arrays Pointers and arrays are strongly related. In fact, pointers and arrays are interchangeable.
Pointers A variable that holds an address value is called a pointer variable, or simply a pointer.  What is the data type of pointer variables? It’s not.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Constants, Data Types and Variables
Fundamentals 2.
Overview Working directly with memory locations is beneficial. In C, pointers allow you to: change values passed as arguments to functions work directly.
Pointers What is the data type of pointer variables?
Intro to Pointers in C CSSE 332 Operating Systems
Course Contents KIIT UNIVERSITY Sr # Major and Detailed Coverage Area
Variables Mr. Crone.
EPSII 59:006 Spring 2004.
void Pointers Lesson xx
Basic notes on pointers in C
DATA HANDLING.
Introduction to Programming
Windows Programming Lecture 02.
Storing Information Each memory cell stores a set number of bits (usually 8 bits, or one byte) (byte addressable)
Introduction to C++ Programming Language
Lecture 1. Program Surgery
Pointers The C programming language gives us the ability to directly manipulate the contents of memory addresses via pointers. Unfortunately, this power.
Overloading functions
Pointers Chapter 11 Copyright © 2008 W. W. Norton & Company.
C Programming Lecture-8 Pointers and Memory Management
C Programming Pointers
Pointers Chapter 11 Copyright © 2008 W. W. Norton & Company.
Variables and Computer Memory
Chapter 3 Introduction to Classes, Objects Methods and Strings
Pointer Arithmetic By Anand George.
Variables and Constants
Introduction to Pointers
Introduction to Pointers
Introduction to C CS 3410.
Presentation transcript:

Department of Electronic & Electrical Engineering Types and Memory Addresses Pointers & and * operators

Department of Electronic & Electrical Engineering Types of variables. Variables are declared as a given type. Variables must be declared before use. The type tells the compiler: How much memory is needed to store the variable. What operations can be performed on the variable.

Department of Electronic & Electrical Engineering Size of data types The amount of memory required the different data types can vary form one machine to another. The next slide shows typical sizes.

Department of Electronic & Electrical Engineering Typical size of primary data types.

Department of Electronic & Electrical Engineering Memory (32 Linux machine)

Department of Electronic & Electrical Engineering What data type should I use? Depends what precision is required and range. int numberOfFingers=10; float height=1.8; char x=10; /* char stores 8bits or a byte of data */ /* typically used to store characters */ /* encoded as byte values */ double pi= ; /* Hmmm most of these digits will be thrown away ? */ double googol=1e100;

Department of Electronic & Electrical Engineering A little experiment with the debugger

Department of Electronic & Electrical Engineering Address &x is 1004 Address &y 1006 Variables in Memory Memory in bytes Value of x is 5 char x=5; int y=257; 1 (256) y occupies 4 bytes DETAILS DEPEND ON THE MACHINE AND COMPILER

Department of Electronic & Electrical Engineering Address of operator and pointers. The ampersand operator & can be used to find the address of a variable; int x; int *ptr; /* ptr is a pointer variable */ /* 4 bytes for 32 bit */ /* 8 bytes for 64 bit */ ptr = &x; /* ptr points at x */ *ptr = 5; /* dereferencing a pointer */ * " contents of the memory location... " & " address of... " referencing dereferencing

Department of Electronic & Electrical Engineering Illustration --- Pointers int x ; int *ptr=&x ; *ptr= x is stored at memory location 1024 the ptr variable contains the address of x

Department of Electronic & Electrical Engineering Recap Variables have a type stored at an address in memory. Different types need different amounts of memory & address of operator (referencing) * contents of address operator (dereferencing)