जरूरी है और सॉफ्टवेयर बनाने के लिए कंप्यूटर की जानकारी | Introduction t...

The ‘goto’ keyword

            Use of ‘goto’ takes the control where you want.  Though it is easy to use, it should be avoided.  The big problem with ‘goto’ is that we can never be sure how we got to a certain point in our code.

Functions

            A function is a self-contained block of statements that performs a task of some kind.  Every C== program can be thought of as a collection of these functions using a function is like hiring a person to do a specific job for you.  The following points can be noted :

(i)                 Any C program contains at least one function.  It must be main ( ).
(ii)               If there are more than one functions in a program, then one must be main ( ).
(iii)       There is no limit on the number of functions that might be present in a program.
(iii)             Each function is called in the sequence specified by the function calls in main ( ).
(iv)             After each function has done its job, control returns to main ().
(v)               A function is called when the function name is followed by a semicolon (;), for example :

Main( )
{
            sum( );
}
(vi)       A function is defined when function name is followed by a pair of braces, in which one or more statements may be present, for example :

                        sum ( )
                        {
                                    statement 1;
                                    statement 2;
                                    statement 3;
                        }
(vii)      Any function can be called from any other function.  Even main ( ) can be called from other functions.

(viii)     A function can be called any number of times.

(ix)             A function can call itself.  Such a process is called ‘recursion’.
(x)               A function cannot be defined in another function.
(xi)             There are basically two types of functions :
(a)                Library functions, e.g – printf( ), getch( ), clrser( ) etc.
(b)               User-defined functions, e.g – sum ( ), prime( ) etc.

(xii)      There is no restriction on the number of ‘return’ statements in a function.  Also the ‘return’ statement need not always be present at the end of the called function.
           
(xiii)         A function can return only one value at a time.
(xiv)         If we want that a called function should not return any value, then we must use keyword ‘void’ before its name. e.g -

void display ( )
                                    {
                                                cout<<”\n Heads I Win …..”;
                                                cout<<”\n Tails you lose.”;

                                    }

Comments

Popular posts from this blog

Learn MS Word -Easy Tutorials | THEORY/ PRACTICAL SESSION | PART 1