Ch7 - CSEB114: Chapt er 7 Point er s pr epar ed by NI edit...

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

View Full Document Right Arrow Icon
Click to edit Master subtitle style 9/5/2008 prepared by NI, edited by CSEB 114: Principle of Programming Chapter 7: Pointers
Background image of page 1

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

View Full Document Right Arrow Icon
9/5/2008 prepared by NI, edited by Objectives In this chapter you will learn about, Basic concept of pointers Pointer variables Pointer declaration Pointer definition and initialization Parameter passing by reference
Background image of page 2
9/5/2008 prepared by NI, edited by What is a pointer So far, we have seen that a variable is used to store a value. Variables allow the programmer to directly manipulate the data in memory. A pointer variable, however, does not store a value but store the address of the memor y space which contain the value i.e. it directly points to a specific memor y address.
Background image of page 3

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

View Full Document Right Arrow Icon
9/5/2008 prepared by NI, edited by Variable declaration  A variable declaration such as, int number = 20; causes the compiler to allocate a memory location for the variable number and store in it the integer value 20. This absolute address of the memory location is readily available to our program during the run time. The computer uses this address to access its content. number 20 number directly references a variable whose value is 7 11001100
Background image of page 4
9/5/2008 prepared by NI, edited by Pointer declaration General Format: data_type *pointer_name; A pointer declaration such as, int *numberPtr; declares numberptr as a variable that points to an integer variable . Its content is a memor y address. The * indicates that the variable being declared is a pointer variable instead of a normal variable.
Background image of page 5

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

View Full Document Right Arrow Icon
9/5/2008 prepared by NI, edited by Pointer declaration cont… Consider the following declaration int *numberPtr, number = 20; In this case, two memory address have been reserved in the memory, namely the numberPtr and number. 20 11001100 11111111 number *numberPtr
Background image of page 6
9/5/2008 prepared by NI, edited by Pointer Initialization To prevent the pointer from pointing to a random memory address, it is advisable that the pointer is initialized to 0, NULL or an address before being used.
Background image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 21

Ch7 - CSEB114: Chapt er 7 Point er s pr epar ed by NI edit...

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

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