Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Pointers in C: Passing Pointers to Functions, Study notes of Software Engineering

How pointers work in c programming language, focusing on passing pointers as arguments to functions. It covers the concept of actual parameters being modified, the use of pointers to change values, and common pitfalls when working with pointers. Students will learn how to modify function parameters by passing pointers and understand the importance of assigning correct addresses to pointers.

Typology: Study notes

Pre 2010

Uploaded on 08/19/2009

koofers-user-rz8
koofers-user-rz8 🇺🇸

10 documents

1 / 8

Toggle sidebar

Related documents


Partial preview of the text

Download Pointers in C: Passing Pointers to Functions and more Study notes Software Engineering in PDF only on Docsity! POINTERS IN C, PASSING POINTERS TO FUNCTIONS CSSE 120—Rose Hulman Institute of Technology Can functions modify actual parameters?  In Python, no! (pass by value)  Consider this function: void downAndUp(int takeMeHigher, int putMeDown){ takeMeHigher += 1; putMeDown -= 1; }  How is this C function invoked?  downAndUp(up, down);  Will calling the function change the values of the actual parameters up and down? Pointer Assignments int x=3, y = 5; int *px = &x; int *py = &y; printf("%d %d\n", x, y); *px = 10; printf("%d %d\n", x, y); /* x is changed */ px = py; printf("%d %d\n", x, y); /* x not changed */ *px = 12; printf("%d %d\n", x, y); /* y is changed */ Break Bw eee O Starring Binky! o (See http://cslibrary.stanford.edu/104/) Pointer Pitfalls  Don't try to dereference an unassigned pointer:  int *p; *p = 5; /* oops! Program probably dies! */  Pointer variables must be assigned address values.  int x = 3; int *p; p = x /* oops, RHS should be &x */  Be careful how you increment  *p +=1; /* is not the same as … */  *p++;