t13BPointersPassByReference

t13BPointersPassByReference - Pointers Call-by-Reference...

Info icon This 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
Image of page 1

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

View Full Document Right 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 & & 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 *number used as nickname for the actual variable passed used as nickname for the actual variable passed www.kite-legends.blogspot.com
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 Call function Define function Program Output
Image of page 3

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern