lec09-pointers

lec09-pointers - CSC 1111 Introduction to Computing using C...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CSC 1111 Introduction to Computing using C++ Pointers
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Questions to be answered … What is a pointer in C++? What do we use pointers for in C++? How to use pointers in C++?
Background image of page 2
3 Introduction Pointers in C++ == Memory Addresses Through pointers, we can directly access/modify the data stored in the memory.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 What do we use pointers for in C++? Exchange data with other programs Programs written in different programming languages Device drivers – Software components that handles direct interaction with hardware devices Dynamic memory management We can decide how much memory space we want at run- time . To emulate passing parameters by reference C language still uses pointers to achieve the effect of pass-by-reference.
Background image of page 4
5 Computer Memory 100 101 102 103 104 105 106 107 108 109 110 Continuous storage of 1-byte cells Each cell has a unique address between 0 and 2 N – 1. Store 1 byte or 8 bits of data Memory Address
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Computer Memory Conceptually, the computer memory is a continuous storage divided into multiple 1-byte cells. Each cell has a unique address ranging from 0 to 2 N -1 in increasing order. N = # of bits of data the processor can process at a time On most computers we use today, N = 32.
Background image of page 6
7 Variables and Memory Addresses Each variable is allocated an appropriate amount of memory space. Each variable has a unique memory address. In this example, what is the address of ch and x ? Do addresses have any relationship with data type? char ch ; // 1 byte int x ; // 32-bit integer (needs 4 bytes) 100 101 102 103 104 105 106 107 108 109 110
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 Variables and Memory Addresses Each variable in the program is allocated an appropriate number of cells in the memory for storing data. ch: 1 byte
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

Page1 / 28

lec09-pointers - CSC 1111 Introduction to Computing using C...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online