Program
#include <stdio.h>
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 <stdio.h>
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 <stdio.h>
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
- In Case 1, the function is written after main, so you have to write the prototype definition in main as given in statement D.
- 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.
- 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:
Post a Comment