Hi All,
Please see the code below.
This is the problem.
The solution of the problem is given below.Code:#include<stdio.h> void change() { /*Write something in this function so that the output of printf in main function should give 5 . Do not change the main function */ } int main() { int i=5; change(); i=10; printf("%d",i); getch(); return 0; }
Now my Question is how does it Work ? since macro is define in the function i.e. it becomes local to function then how the out put of printf has changed?Code:#include<stdio.h> void change() { /*Write something in this function so that the output of printf in main function should give 5 . Do not change the main function */ #define printf(fmt,x) printf ( "%d\n", 5 ) } int main() { int i=5; change(); i=10; printf("%d",i); getch(); return 0; }
Regards,
x8086




Reply With Quote