📖 Samacheer Kalvi · 11th TN - English Medium · Computer Science · Page 186question

Introduction to C++ · Part 7

Chapter 3: 4 · Computer Science

base = ; exponent = ; result = pow(base, exponent); cout << "pow("<<base << "^" << exponent << ") = " << result; double x = ;; result = sin(x); cout << "\nsin("<<x<<")= "<<result; return ; Output: pow( ^ ) = sin( )= - .132352 Program . Chapter Page - - . User-defined Functions . .

Introduction We can also define new functions to perform a specific task. These are called as user-defined functions . User-defined functions are created by the user. A function can optionally define input parameters that enable callers to pass arguments into the function.

A function can also optionally return a value as output. Functions are useful for encapsulating common operations in a single reusable block, ideally with a name that clearly describes what the function does. . .

Function Definition In C++, a function must be defined before it is used anywhere in the program. The general syntax of a function definition is: Function_ name(parameter list) Body of the function Note: . The is any valid data type of C++. .

The is a user-defined identifier. . The parameter list, which is optional, is a list of parameters, i.e. a list of variables preceded by data types and separated by commas.

. The body of the function comprises C++ statements that are required to perform the intended task of this function. . .

Function Prototype C++ program can contain any number of functions. But, it must always have only one main() function to begin the program execution. We can write the definitions of functions in any order as we wish. We can define the main() function first and all other functions after that or we can define all the needed functions prior to main().

Like a variable declaration, a function must be declared before it is used in the program. The declaration statement may be given outside the main() function. long fact (int, double) Function name List of arguments Return type long fact (int, double) Figure . The prototype above provides the following information to the compiler: • The return value of the function

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →