by Dinesh Thakur

Auto

 

The values of the variables are not retained beyond the scope of a function in which they are declared. The values of the variables can be accessed only during the execution of a function. Whatever variables are declared in a function, they are assumed implicitly of auto storage type. For example in the following program segment

 
by Dinesh Thakur

Arguments in a function can also be of array type. When the arrays are passed by value in a function, it is written as shown in the following example:

 
by Dinesh Thakur

A recursive function is a function which invokes itself repeatedly. In this case function name appears within the function. Two examples of recursive function are given as follows:

 
by Dinesh Thakur

A function can also return values to the calling program. For such functions, the type of the value returned to the calling function should be mentioned before the function name in the definition. The general syntax of a function which returns value is:

 
by Dinesh Thakur

A function contains a set of statements which can be invoked from any part of the program. Function plays an important role whenever a sequence of instructions is to be repeated in a program. Thus it helps in reducing the size of the program. The function code is stored at only one place in the memory, though the function can be executed any number of times. Main () is also a function. Every program must contain the main () function. A function mayor may not return values to the calling function.



 
by Dinesh Thakur

In some cases when a similar action is to be performed on different types of data, different functions having different names are to be defined for all types of data. This makes the program very complex as the programmer must keep a track of the names of all the functions defined in the program. To prevent such situations, C++ allows the functions to be overloaded.

 
by Dinesh Thakur

Any value assigned to an automatic variable within a function is lost once the control returns from the called function to the calling function. However, there may be a situation where the value of the local variable needs to be preserved even after the execution of the function gets over. This need can be fulfilled by declaring the variable as static. A static variable is commonly used when it is necessary for a function to remember a value between its calls. To understand the concept of static variables, consider this example.

 
by Dinesh Thakur

Like C, C++ enables to pass arguments to the main () function also. These arguments are passed by typing them after the program name on the command line. Hence, these arguments are known as command line arguments. Command line arguments help in providing data to the program.

 
by Dinesh Thakur

In addition to call by value, a function can also be called by reference. C++ provides two ways of passing arguments as reference to a function. The arguments can be passed either as a reference type or as a pointer type.

 
by Dinesh Thakur

When a function is called by value, the values of the actual arguments are copied into the formal arguments and the function works with these copied values. As a result, any changes made to the copied value in the called function do not affect the value of the actual argument in the calling function.

 
by Dinesh Thakur

In order to use a function in different parts of a program, the function must be called or invoked by another function. In C++, functions are called by specifying the name of the function, followed by the parentheses. The parentheses mayor may not contain a list of arguments depending on the function definition.

 
by Dinesh Thakur

In order to use a function in a program, the function must be first defined somewhere in a program. A function definition contains the code that specifies the actions to be performed. The syntax for defining a function is

 
by Dinesh Thakur

Like variables, functions also need to be declared before they are used in programs. A function declaration is also known as function prototype. Function prototype is a model or a blueprint for a function that informs the C++ compiler about the return type, the function name, and the number and data type of the arguments passed to the function. Function name together with parameter list is known as function signature and it does not include return type of a function. The syntax for declaring a function is



 
by Dinesh Thakur

strcpy () : If Sl and S2 are the names of two strings, the function call strcpy (S1, S2) copies

the contents of S2 including null character on to Sl. If S2 is smaller than Sl, there is no problem, however, if S2 is bigger than Sl the operation will eat into adjacent memory.



 
by Dinesh Thakur

 The function strcmp () is widely used in sorting of lists of names. Let S1 and S2 be the names of two strings. The function compares lexicographically (dictionary style) string S1 with string S2. It returns -1, 0, 1, respectively, if S1 is less than S2 , equal to S2, or greater than S2. Program illustrates its application.

 
by Dinesh Thakur

Whenever a function is invoked, a set of operations is performed which includes passing the control from the calling function to the called function, managing stack for arguments and return values, managing registers, etc. All these operations take much of compiler time and slow down the execution process. This overhead can be avoided by using macros in a program. However, macros are not considered as true functions, as they do not perform type checking. Another way to make function calls execute faster and also perform type checking is to make the function inline.



 
by Dinesh Thakur

Function overloading: C++ enables several functions of the same name to be defined, as long as these functions have different sets of parameters (at least as far as their types are concerned). This capability is called function overloading. When an overloaded function is called, the C++ compiler.

 
by Dinesh Thakur

As we know that when we call the Member Function from the Class then the Compiler will jump to that Function and after Executing all the Statements the Compiler will execute the Remaining Statements.

 
by Dinesh Thakur

As we know that Private data of a Class can’t be Accessed with the help of an Object. Means if a Class Contains Some Data Members those are Private in nature then we cant Accessed those data Members with the help of an Object, from Outside the Class. So that if we want to do this. Then we must have to use the Friend Function. If a Function declared by using the Friend Keyword, then they can use the Private Data of a Class with the help of an Object.

 
by Dinesh Thakur

As we Know that For Accessing any thing means Data Members and Member Functions from a Class we must have to Create an Object First, So that When we Creates an Object of Class , then all the Data of Class will be Copied into an Object so that this will Consume Some Memory So that double Memory will be used for Storing the Data of single Class. First, Memory used by Class for storing his data and Second by Object.

 
by Dinesh Thakur

Functions are used for Placing or Storing the Code which is to be Repeated Several Times. For Example, if we need Same Code, then we must have to Write that Code Again and Again So that for Removing this Task, we uses functions.

 
by Dinesh Thakur

As the name suggest Override means to hide or Remove the Detail which is already Exists .Method or Function Overriding always Occur in the Inheritance, when a base Class and Derived Class both have a same name of Method. Then we will call that Method then this will Call the Method of Derived Class and Override the Body of Base Class Method.

 
by Dinesh Thakur

1) Call by Value:-when we call a Function and if a function can accept the Arguments from the Called Function, Then we must have to Supply some Arguments to the Function. So that the Arguments those are passed to that function just contains the values from the variables but not an Actual Address of the variable.

 
by Dinesh Thakur

When a Function can call itself again and Again or When a Function call itself until a Condition is not to be False. When a function definition includes a call to itself, it is referred to as a recursive function and the process is known as recursion or circular definition. In this a function call itself repeatedly. In the Recursion we just have to make a One Time call and the will automatically call itself Again and Again.