DATA STRUCTURE & ALGORITHMS Pointers & Structure.

Slides:



Advertisements
Similar presentations
Incomplete Structs struct B; struct A { struct B * partner; // other declarations… }; struct B { struct A * partner; // other declarations… };
Advertisements

An introduction to pointers in c
C Structures and Memory Allocation There is no class in C, but we may still want non- homogenous structures –So, we use the struct construct struct for.
1 Structures. 2 User-Defined Types C provides facilities to define one’s own types. These may be a composite of basic types ( int, double, etc) and other.
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.
Data Structures (Second Part) Lecture 2 : Pointers Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
Review for Final Exam Dilshad M. NYU. In this review Arrays Pointers Structures Java - some basic information.
Winter2015 COMP 2130 Intro Computer Systems Computing Science Thompson Rivers University C: Advanced Topics.
Pointers Typedef Pointer Arithmetic Pointers and Arrays.
Dale/Weems/Headington
CS Sept Your first C++ program… Boilerplate // Cannon, demo program #include using namespace std; int main() {// program goes here… return.
Data Structures Lecture 3: Struct Azhar Maqsood NUST Institute of Information Technology (NIIT)
16/19/2015 1:14 PM6/19/2015 1:14 PM6/19/2015 1:14 PMArrays and Structures Methods to manipulate a collection of values under one name. Arrays: Homogenous.
Structs. Structures We already know that arrays are many variables of the same type grouped together under the same name. Structures are like arrays except.
DCT1063 Programming 2 CHAPTER 5 ADVANCED DATA TYPE (part 1) Mohd Nazri Bin Ibrahim Faculty of Computer Media and Technology TATi University College
Arrays in C++ Numeric Character. Structured Data Type A structured data type is a type that stores a collection of individual components with one variable.
February 11, 2005 More Pointers Dynamic Memory Allocation.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
Pointer Data Type and Pointer Variables. Objectives: Pointer Data Type and Pointer Variables Pointer Declaration Pointer Operators Initializing Pointer.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 4 Pointers and Dynamic Arrays Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
Dynamic memory allocation and Pointers Lecture 4.
Current Assignments Start Reading Chapter 6 Project 3 – Due Thursday, July 24 Contact List Program Homework 6 – Due Sunday, July 20 First part easy true/false.
1 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University.
1 Chapter 11 Structured Data. 2 Topics 10.1 Abstract Data Types 10.2 Combining Data into Structures 10.3 Accessing Structure Members 10.4 Initializing.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Structured Data Chapter 11. Combining Data Into Structures Structure: C++ construct that allows multiple variables to be grouped together Format: struct.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Welcome to Concepts Pointer Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्जेण्डर )PGT(CS) KV JHAGRAKHAND.
Welcome to Concepts of Pointers. Prepared by:- Sumit Kumar PGT(Computer Science) Kv,Samba.
Objective: Students will be able to: Declare and use variables Input integers.
Structured Programming Approach Module VIII - Additional C Data Types Structures Prof: Muhammed Salman Shamsi.
Lecture – Pointers1 C++ Pointers Joseph Spring/Bob Dickerson School of Computer Science Operating Systems and Computer Networks Based on notes by Bob Dickerson.
1 Chapter 12 Arrays. 2 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating.
Pointer. lvalues In C++, any expression that refers to an internal memory location is called an lvalue Appear on left side of assignment statement e.g.
POINTERS IN C. Introduction  A pointer is a variable that holds a memory address  This address is the location of another object (typically another.
Lecture 7.  There are 2 types of libraries used by standard C++ The C standard library (math.h) and C++ The C++ standard template library  Allows us.
Introduction to C Zhengwei Yang CSC2100 Data Structures Tutorial 1.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 7 – Pointers.
Pointers 1. Introduction Declaring pointer variables Pointer operators Pointer arithmetic 2 Topics to be Covered.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
A Sample Program #include using namespace std; int main(void) { cout
1 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating float double long.
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.
Bill Tucker Austin Community College COSC 1315
Pointers What is the data type of pointer variables?
EGR 2261 Unit 11 Pointers and Dynamic Variables
MT262A Review.
Chapter 10-1: Structure.
Introduction to C++ October 2, 2017.
Visit for more Learning Resources
Pointers Psst… over there.
Basic notes on pointers in C
Pointer Data Type and Pointer Variables
Dynamic Memory Allocation Reference Variables
Pointers Psst… over there.
Buy book Online -
Structures Lesson xx In this module, we’ll introduce you to structures.
Linked List Lesson xx   In this presentation, we introduce you to the basic elements of a linked list.
Structure ការណែនាំអំពី Structure
Pointer to Structures Lesson xx
From C to C++: Summary of weeks 1 - 4
C Programming Lecture-8 Pointers and Memory Management
C Programming Pointers
A simple function.
Creating and Using Pointer Variables in C++ By: Ed Brunjes
Pointers and dynamic objects
Pointer Data Type and Pointer Variables
Pointer Data Type and Pointer Variables
Presentation transcript:

DATA STRUCTURE & ALGORITHMS Pointers & Structure

POINTERS IN C++ Pointers is an extremely powerful programming tool Make some things much easier, help improves program’s efficiency Possible to use pointers to dinamically allocate memory

WHAT ARE POINTERS? Pointers are just variables that store memory addresses, usually the addresses of other variable For example, in our daily life a pointer is like a safety deposit boxes that stored in another safety box

C++ POINTER SYNTAX Pointers require a bit of new syntax because when you have a pointer, you need the ability to request both the memory location it stores and the value stored at the memory location Pointer declaration: * ; For eg. u could declare a pointer that stores the address of an integer with the following syntax: int *points_to_integer;

POINTING TO SOMETHING To get the memory address of a variable (its location in memory), put the ‘&’ sign in front of the variable name. This is called the address-of operator, because it returns the memory address

SAMPLE CODING #include using namespace std; int main() { int x;//A normal integer int *p;//A pointer to an integer p = &x;//Read it, “assign the address of x to p” cin >> x;//Put a value in x, we could also use *p here cout << *p;//Note the use of the * to get the value }

STRUCTURES Structures are a way of storing many different values in variables of potentially different types under the same name It generally useful whenever a lot of data needs to be grouped together – for instance The format for defining a structure: struct Tag { Members }; Tag is the name of the entire type of srtucture and Members are the variables within the struct

SAMPLE CODING struct database { int id_number; int age; float salary; }; int main() { database employee; employee.age = 22; employee.id_number = 1; employee.salary = 12000; }

End of chapter