What is the output of the following code?

# define i 20
main()
{
printf("%d..",i);
fun();
printf("%d",i);
}
void fun()
{
#undef i
#define i 30
}

Options
- 20..30
- 20..20
- 0
- Error


CORRECT ANSWER : 20..20

Discussion Board
Answer- 20..20

It will compile, with warning 'implicit declaration of function 'fun'. To avoid this warning must define the prototype of function before main function or write function 'fun' before the main function.

But in this program, if we write 'fun' function before the main then output is 30..30 and if function writes after main then output is 20..20.


Sapna 02-17-2017 12:09 AM

Answer is ERROR..!!

[Error]'fun()' was not declare in this scope.

Tahir 05-29-2016 01:57 AM

good answer

it will compile, correct answer 20..20.. , if you put the fun function before the main it will be 30..30..

paul 10-8-2014 05:41 AM

Ans is ERROR.

Because if we define the function after main() we should declare that function before the main.

SAI KUMAR 09-12-2014 05:38 AM

to test my c knowledge

this test is very useful to test my skill.THANK YOU


keerthana.B 07-9-2014 07:48 AM

wrong answer

It will not compile. It is using fun() before it was declared.

laca 05-11-2014 10:53 AM

correct answer

undef scope is only inside fun()

ajinkya 04-24-2014 09:07 AM

Write your comments


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement