operator Used as aliasnickname for variable inside of function void double int

Operator used as aliasnickname for variable inside of

This preview shows page 5 - 10 out of 16 pages.

the caller’s memory. * operator Used as alias/nickname for variable inside of function void double( int *number ) { *number = 2 * ( *number ); } *number used as nickname for the variable passed Quick yak: When a customer puts the request in Vending m achine for a particular drink , then he has to pass the address of drink as an argument to function.
Image of page 5
Program to call function by value The original value of number is 5 The new value of number is 5
Image of page 6
©LPU CSE101 C Programming int main() { int number = 5 ; number=cubeByValue(number); } int cubeByValue( int n ) { return n * n * n; } number 5 n Before function call undefined int main() { int number = 5 ; number = cubeByValue( number ); } int cubeByValue( int n ) { return n * n * n; } number 5 n After function receives call 5 125 int cubeByValue( int n ) { return n * n * n; } int main() { int number = 5 ; number = cubeByValue( number ); } number 5 n After function computes n and before it returns to main 5 Fig. Analysis of a typical call-by-value. (Part 1 of 2.)
Image of page 7
©LPU CSE101 C Programming 125 int main() { int number = 5 ; number = cubeByValue( number ); } int cubeByValue( int n ) { return n * n * n; } number 5 n After function returns to main and before assigning result to number undefined 125 125 int main() { int number = 5 ; number = cubeByValue( number ); } int cubeByValue( int n ) { return n * n * n; } number 125 n After main completes the assignment to number : undefined
Image of page 8
Notice how the address of number is given - cubeByReference expects a pointer (an address of a variable).
Image of page 9
Image of page 10

You've reached the end of your free preview.

Want to read all 16 pages?

  • Spring '18
  • Aman
  • cubeByReference

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

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors