blogger Indonesia

Follow judhyns blog

CALLING FUNCTION

Introduction

When a function is written before main it can be called in the body of main. If it is written after main then in the declaration of main you have to write the prototype of the function. The prototype can also be written as a global declaration.

Program

Case 1: #include  main ( ) {     int i;     void (int *k)         // D      i = 0;     printf (" The value of i before call %d \n", i);     f1 (&i);         // A     printf (" The value of i after call %d \n", i); } void (int *k)            // B {     *k = *k + 10;        // C }  Case 2:  #include  void (int *k)            // B {     *k = *k + 10;        // C }  main ( ) {     int i;     i = 0;     printf (" The value of i before call %d \n", i);     f1 (&i);         // A     printf (" The value of i after call %d \n", i); }  Case 3: #include  void f1(int *k)                  // B {     *k = *k + 10;        // C } . main ( ) {     int i;     i = 0; printf ("The value of i before call %d \n", i);     f1 (&i);         // A printf ("The value of i after call %d \n", i); } 

Explanation

  1. In Case 1, the function is written after main, so you have to write the prototype definition in main as given in statement D.

  2. In Case 2, the function is written above the function main, so during the compilation of main the reference of function f1 is resolved. So it is not necessary to write the prototype definition in main.

  3. In Case 3, the prototype is written as a global declaration. So, during the compilation of main, all the function information is known.

No comments:

feed

PR Check

activesearchresults

judhyn's blog

 

http://www.judhyn.blogspot.com | |