Lecture Slides on Pointers | C Programming for Engineers | CSE A205, Study notes of Engineering

Material Type: Notes; Class: Introduction to C Programming for Engineers; Subject: Computer Systems Engineering ; University: University of Alaska - Anchorage; Term: Fall 2008;

Typology: Study notes

Pre 2010

Uploaded on 03/28/2010

koofers-user-rb9-1
koofers-user-rb9-1 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE294A
Introduction to C Programming for Engineers
Lecture #13
Jeffrey Miller, Ph.D.
pf3
pf4
pf5

Partial preview of the text

Download Lecture Slides on Pointers | C Programming for Engineers | CSE A205 and more Study notes Engineering in PDF only on Docsity!

CSE294A

Introduction to C Programming for Engineers

Lecture

Jeffrey Miller, Ph.D.

Pointers

Pointers enable programs to simulate call-by-reference and to create and manipulate dynamicdata structures (which are data structures that cangrow and shrink at run time)

Pointers are variables whose values are memoryaddresses

All of the scalar variables we have discussedcontain specific values, not memory addresses

Pointer Values

What is the output of each of the printf statements below?

int *count_ptr; int count = 10; count_ptr = &count; printf (“%d”, count); printf (“%d”, *count_ptr); printf (“%d”, count_ptr); printf (“%d”, &count); printf (“%d”, &count_ptr);

Pass by Reference

Using pointers, we can now pass variables by reference

void change_value (int *my_ptr)

*my_ptr

} void change_value (int val)

val

} void main()

int value

int *value_ptr; value_ptr

&value; printf (“%d”, value);

what is printed? change_value(value); printf (“%d”, value);

what is printed? change_value(value_ptr); printf (“%d”, value);

what is printed? change_value(&value); printf (“%d”, value);

what is printed? }

Homework

Homework #6 is posted!