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 Guides, Projects, Research of Software Engineering

How functions can modify actual parameters in c by passing pointers to them. It covers the concept of pointers, how to modify values using pointers, and common pitfalls when working with pointers. Students will learn how to implement a function that passes pointers to values to be changed and how to avoid common pointer errors.

Typology: Study Guides, Projects, Research

Pre 2010

Uploaded on 08/17/2009

koofers-user-nt0
koofers-user-nt0 🇺🇸

10 documents

1 / 8

Toggle sidebar

Related documents


Partial preview of the text

Download Pointers in C: Passing Pointers to Functions and more Study Guides, Projects, Research 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 1. int x=3, y = 5; 2. int *px = &x; 3. int *py = &y; 4. printf("%d %d\n", x, y); 5. *px = 10; 6. printf("%d %d\n", x, y); /* x is changed */ 7. px = py; 8. printf("%d %d\n", x, y); /* x not changed */ 9. *px = 12; 10. printf("%d %d\n", x, y); /* y is changed */ Break 7 eee O Starring Binky! Oo (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++;
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved