t13BPointersPassByReference

t13BPointersPassByReference - Pointers Call-by-Reference...

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

View Full Document Right Arrow Icon
Dale Roberts Pointers Call-by-Reference www.kite-legends.blogspot.com
Background image of page 1

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

View Full DocumentRight Arrow Icon
Dale Roberts Calling Functions by Reference Calling Functions by Reference Call by reference with pointer arguments Call by reference with pointer arguments Pass address of argument using Pass address of argument using operator operator Allows you to change actual location in memory Allows you to change actual location in memory Arrays are not passed with Arrays are not passed with because the array name is already a because the array name is already a pointer pointer * * Operator Operator Used as formal parameter for variable inside of function Used as formal parameter for variable inside of function void double_num ( int *number ) void double_num ( int *number ) { *number = 2 * ( *number ); *number = 2 * ( *number ); } *number *number used as nickname for the actual variable passed used as nickname for the actual variable passed www.kite-legends.blogspot.com
Background image of page 2
Dale Roberts 1 /* 2 Cube a variable using call-by-value 3 */ 4 5 #include <stdio.h> 6 7 int cubeByValue( int ); /* prototype */ 8 9 int main() 10 { 11 int number = 5; 12 13 printf( "The original value of number is %d", number ); 14 number = cubeByValue( number ); 15 printf( "\nThe new value of number is %d\n", number ); 16 17 return 0; 18 } 19 20 int cubeByValue( int n ) 21 { 22 return n * n * n; /* cube number in main */ 23 } The original value of number is 5 The new value of number is 125 Function prototype Initialize variables
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/08/2010 for the course CSE 2017 taught by Professor Kittu during the Spring '10 term at APIIT.

Page1 / 8

t13BPointersPassByReference - Pointers Call-by-Reference...

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

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