 Review structures  Program to demonstrate a structure containing a pointer.

Slides:



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

STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Template Implicit function overload. Function overload Function overload double ssqq(double & a, double & b) { return(a*b);} float ssqq(float & a, float.
1 Class Vehicle #include #define N 10../.. 2 Class Vehicle class vehicle { public: float speed; char colour[N+1]; char make[N+1];
1 Pointers Lecture Introduction Pointers  Powerful, but difficult to master  Simulate pass-by-reference  Close relationship with arrays and.
CS 141 Computer Programming 1 1 Pointers. Pointer Variable Declarations and Initialization Pointer variables –Contain memory addresses as values –Normally,
Informática II Prof. Dr. Gustavo Patiño MJ
Pointers. Addresses in Memory When a variable is declared, enough memory to hold a value of that type is allocated for it at an unused memory location.
Pointers 1 Pointers Pointers  In chapter three we looked at passing parameters to functions using call by value, and using call by reference, using reference.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 6 : September 6.
Create your own types: typedef #define N 3 typedef double scalar; /* note defs outside fns */ typedef scalar vector[N]; typedef scalar matrix[N][N]; /*
Esempi Puntatori e Stringhe1 // This program puts values into an array, sorts the values into // ascending order, and prints the resulting array. #include.
 Write a program that uses a one dimension to do a table look-up  Learn about parallel arrays.
Addresses in Memory When a variable is declared, enough memory to hold a value of that type is allocated for it at an unused memory location. This is.
Completing the Basic (L06)
C++ Data Types Structured array struct union class Address pointer reference Simple IntegralFloating char short int long enum float double long double.
Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else.
Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.
Selection Control Structures (L08) * Selection Criteria * if Statements * The if-else Statement Selection Control Structure Dr. Ming Zhang.
 for loop  while loop  do-while loop for (begin point; end point ; incrementation ) { //statements to be repeated }
C++ Programming Lecture 13 Functions – Part V The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
System Programming Practical Session 7 C++ Memory Handling.
1 Object-Oriented Programming Using C++ A tutorial for pointers.
1 Advanced Topics in Functions Lecture Unitary Scope Resolution Operator Unary scope resolution operator ( :: )  Access global variable if.
1. Pointers –Powerful, but difficult to master –Simulate pass-by-reference –Close relationship with arrays and strings 2.
 2003 Prentice Hall, Inc. All rights reserved. 1 Lecture 5: Pointer Outline Chapter 5 Pointer continue Call by reference Pointer arithmatic Debugging.
 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers.
Selection Control Structures 2 (L09) * Nested if Statements * The if-else Chain * Exercise: if, if-else, nested if, and if-else chain Selection Control.
 Memory from the heap  Dynamic memory allocation using the new operator  Build a dynamic linked list  Another way of traversing a linked list 
 Working with multiple files  Copying files  Updating files.
Advanced Programming Constants, Declarations, and Definitions Derived Data Types.
Chapter 2 Creating a C++ Program. Elements of a C++ Program Four basic ways of structuring a program Four basic ways of structuring a program 1.Sequencing.
 Review building a complete linked list  List traversal in main ( )  List traversal using a function.
1 Compiler directive: #define, usage 1 #include using namespace std; #define TAX //double TAX=0.08; #define LAST_NAME "Li" #define FIRST_NAME "Dennis"
Lesson xx Why use functions Program that needs a function Function header Function body Program rewritten using a function.
 Data Streams  Numeric Output  Numeric Input  Multiple Numeric Output  Multiple Numeric Input  Character Output  Character Input  String Output.
C++ Programming Lecture 13 Functions – Part V By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
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.
CISC220 Spring 2010 James Atlas Lecture 04: Pointers, Functions, Memory Management, ADTs, Classes, Hardware, Software, Graphics, Networking, AI, Databases,
Popping Items Off a Stack Using a Function Lesson xx
#define #include<iostream> using namespace std; #define GO
Pointers & Arrays.
Two-Dimensional Arrays Lesson xx
Introduction to Programming
Command Line Arguments
Traversing a Linked List
Visit for more Learning Resources
void Pointers Lesson xx
Buy book Online -
Zhen Jiang West Chester University
Linked List Lesson xx   In this presentation, we introduce you to the basic elements of a linked list.
Popping Items Off a Stack Lesson xx
Value returning Functions
Creation and Use of Namespaces
Counting Loops.
Starting Out with C++: From Control Structures through Objects
Pointers & Functions.
Pointer to Structures Lesson xx
Local Variables, Global Variables and Variable Scope
Functions Pass By Value Pass by Reference
Dynamic Memory A whole heap of fun….
Introduction to Programming
5.1 Introduction Pointers Powerful, but difficult to master
Introduction to Programming
Function Overloading.
Pointers & Arrays.
Pointers & Functions.
Type Conversion It is a procedure of converting one data type values into another data type In C programming language we are having two types of type conversion.
The Stack.
CSCE 206 Lab Structured Programming in C
Presentation transcript:

 Review structures  Program to demonstrate a structure containing a pointer

struct card { int pip; char suit; }; int main ( ) { card c; c.pip = 2; c.suit = ‘s’; return 0; } 2 ‘s’ c.pip c.suit c

struct xyz { int a; char b; float c; int *ptr; };

#include using std::cout; using std::endl; struct structWithPtrs { int* p1; double* p2; }; int main() { structWithPtrs s; int i1 = 100; double f2; s.p1 = &i1; s.p2 = &f2; *s.p2 = -45.0; cout << "i1 = " << i1 << " *s.p1 = " << *s.p1 << endl; cout << "f2 = " << f2 << " *s.p2 = " << *s.p2 << endl; return 0; }

struct structWithPtrs { int* p1; double* p2; };

structWithPtrs s; int i1 = 100; double f2; s.p1 = &i1; s.p2 = &f2; *s.p2 = -45.0; s.p1 s.p2 (2fe) s

structWithPtrs s; int i1 = 100; double f2; s.p1 = &i1; s.p2 = &f2; *s.p2 = -45.0; s.p1 s.p2 (2fe) s 100 f2 i1(1ab) (67b)

structWithPtrs s; int i1 = 100; double f2; s.p1 = &i1; s.p2 = &f2; *s.p2 = -45.0; 1ab 67b s.p1 s.p2 (2fe) s 100 f2 i1(1ab) (67b)

structWithPtrs s; int i1 = 100; double f2; s.p1 = &i1; s.p2 = &f2; *s.p2 = -45.0; 1ab 67b s.p1 s.p2 (2fe) s f2 i1(1ab) (67b)

cout << "i1 = " << i1 << " *s.p1 = " << *s.p1 << endl; cout << "f2 = " << f2 << " *s.p2 = " << *s.p2 << endl; 1ab 67b s.p1 s.p2 (2fe) s f2 i1(1ab) (67b) Output i1 = 100 *s.p1 = 100 f2 = *s.p2 = -45.0

Review structures Program to demonstrate a structure containing a pointer