C: Pointers, Arrays, and strings - Boise State University
C: Pointers, Arrays, and
strings
C: Pointers, Arrays, and strings
Department of Computer Science College of Engineering Boise State University
August 25, 2017
1/36
Pointers and Arrays
C: Pointers, Arrays, and
strings
A pointer is a variable that stores the address of another variable.
Pointers are similar to reference variables in Java.
May be used to produce more compact and efficient code (but can be tricky to understand and debug if not used carefully!)
Pointers allow for complex "linked" data structures (e.g. linked lists, binary trees)
Pointers allow for passing function parameters by reference instead of by value.
Pointers and arrays are closely related.
2/36
Memory Organization
C: Pointers, Arrays, and
strings
Memory is an array of consecutively addressed cells. Typical size of each cell is 1 byte. A char takes one byte whereas other types use multiple cells depending on their size.
3/36
Memory Organization
C: Pointers, Arrays, and
strings
Example:
int a = 7; char b = b ;
4/36
Pointer Syntax
C: Pointers, Arrays, and
strings
Address operator (&): gives the address in memory of an object.
p = &c;
// p points to c // (address of c is assigned to p)
Indirection or dereferencing operator (*): Gives access to the object a pointer points to. How to declare a pointer variable? Declare using the type of object the pointer will point to and the * operator.
int *pa; //a pointer that points to an int double *pb; //a pointer that points to a double
5/36
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- arrays and pointers in c rice university
- c programming and embedded systems
- ch 10 characters c strings and characters the string class
- lecture 05 arrays and pointers1
- c pointers gdb
- characters and strings
- 261 more array exercises depaul university
- arrays in c
- 6 087 lecture 5 january 15 2010 mit opencourseware
- chapter 16 pointers and arrays
Related searches
- illinois state university online courses
- illinois state university programs
- illinois state university bachelor degrees
- illinois state university degree programs
- illinois state university online degree
- illinois state university online masters
- illinois state university summer schedule
- illinois state university summer classes
- illinois state university phd programs
- illinois state university online program
- illinois state university majors and minors
- 3rd grade arrays and multiplication