Presentation is loading. Please wait.

Presentation is loading. Please wait.

Function PrototypetMyn1 Function Prototype We can declare a function before we use or define it by means of a function prototype. A function prototype.

Similar presentations


Presentation on theme: "Function PrototypetMyn1 Function Prototype We can declare a function before we use or define it by means of a function prototype. A function prototype."— Presentation transcript:

1 Function PrototypetMyn1 Function Prototype We can declare a function before we use or define it by means of a function prototype. A function prototype is a statement that describes a function sufficiently for the compiler to be able to compile calls to it. It declares the name of the function, its return type, and the types of its parameters. A function prototype is often referred to as a function declaration.

2 Function PrototypetMyn2 A function declaration is similar to a variable declaration in that a function cannot be called within a program file unless the call is preceded in the file by a declaration. We could write the function prototype for our power() function as: double power(double x, int n); If you place the function prototype at the beginning of a program file that contains calls to the function, the compiler will be able to compile the code regardless of where the definition of the function is.

3 Function PrototypetMyn3 The function prototype above is identical to the function header, with a semicolon appended. A function prototype is always terminated by a semicolon, but in general it doesn’t have to be identical to the function header. You can use different names but not different types for the parameters from those used in the definition: double power(double value, int exponent);

4 Function PrototypetMyn4 It could be helpful to use more explanatory names in the function prototype, when such names would be too cumbersome for use in the function definition itself. Since the compiler only needs to know what type each parameter is, you can even omit the parameter names from the prototype: double power(double, int);


Download ppt "Function PrototypetMyn1 Function Prototype We can declare a function before we use or define it by means of a function prototype. A function prototype."

Similar presentations


Ads by Google