0% found this document useful (0 votes)
31 views3 pages

Chapter 6 Advanced Function Features

This document discusses advanced function features in C++ including pass by value vs reference, inline functions, static local variables, and illegal function declarations. It provides examples of calling functions and how variables are treated inside and outside of functions.

Uploaded by

Lau Weng Loon
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views3 pages

Chapter 6 Advanced Function Features

This document discusses advanced function features in C++ including pass by value vs reference, inline functions, static local variables, and illegal function declarations. It provides examples of calling functions and how variables are treated inside and outside of functions.

Uploaded by

Lau Weng Loon
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Chapter 6 Advanced Function Features

1. "Pass by value" is to pass a copy of the value to the function. "Pass by reference" is to pass the reference of the argument to the function. (A) The output of the program is 0, because the variable max is not change by invo!ing the function max. (") The output of the program is #, because the a ress of variable max is passe to the max$alue function. # is assigne to variable max in the function. (") "efore the call, variable times is % n&% 'elcome to ())* n&# 'elcome to ())* n&1 'elcome to ())* After the call, variable times is % (() # #+ #+, # + , 1# + , 1- %# # + , 1- %# -+ (.) 1 #1 #1 +#1 i is / #.

1pace re2uire for the max metho max3 0 value#3 # value13 1 1pace re2uire for the main metho max3 0 1pace re2uire for the main metho max3 0

1pace re2uire for the max metho max3 # value#3 # value13 1 1pace re2uire for the main metho max3 0 1pace re2uire for the main metho max3 0

0ust before max is invo!e .

0ust entering max.

0ust before max is returne

4ight after max is returne

%. x is 1# y is 10 +. 'hen invo!ing p(!), the compiler cannot etermine 5hich function to call. 6t is ambiguous. /. This is a common programming error. "e careful. .on7t eclare the parameters in the program because they are alrea y eclare in the function hea er. max an min are alrea y eclare in the function hea er, an shoul not be re eclare in the funciton. -. 8 is a global variable. i is a local variable. 9lobal variables are efaulte to 0 an local variables are not initiali:e . 1o i can have any value an 8 is 0. ;. 8 in line + is a global variable. i is a local variable. 8 insi e the function p is a static local variable. The output is
i is 6 j is 6 i is 6 j is 7 global j is 40

,.

<ine %3 int i & / is 5rong since n is alrea y eclare in the function signature.

=. Inline functions are not called; rather, the compiler copies the function code in line at the point of each invocation. To specify an inline function, precede the function declaration with the inline keyword. 10. The follo5ing are illegal.
void t1(int x, int y = 0, int !;

void t"(int x = 0, int y = 0, int

!;

You might also like