What is the output of below code?
main()
{
static in a=5;
printf("%3d",a--);
if(a)
main();
}

Answers were Sorted based on User's Feedback



What is the output of below code? main() { static in a=5; printf("%3d",a--); if(a) m..

Answer / srinivas reddy m v

54321

here main() is called again in main function
this leads to recursion....

the function is called until a become 0.
value is retained as static key word is used.

not much clear about usage of "%3d"

Is This Answer Correct ?    10 Yes 1 No

What is the output of below code? main() { static in a=5; printf("%3d",a--); if(a) m..

Answer / amol subhash kumbhar

Output is:- 5 4 3 2 1 (This Manner)
In main()
Static is the Preserves Keyword Used to Statically allocate
the memory allocation
%3d means the 3 space are allocate in the output like as 5
4 3 2 1
main() :- main function called in main function means
recursion is applied

Is This Answer Correct ?    5 Yes 0 No

What is the output of below code? main() { static in a=5; printf("%3d",a--); if(a) m..

Answer / pratik panchal

output:5 4 3 2 1

static int store the value of variable for once and
periodically changes its value as the variable value changes
and a-- is done so the assigned value on the next line will
automatically overwrite the value of a.

%3d means print 5 then 2 spaces and 4 and so on..,.main is
called until if statement gets false..if(5) is a true
condition.

Is This Answer Correct ?    1 Yes 0 No

What is the output of below code? main() { static in a=5; printf("%3d",a--); if(a) m..

Answer / moloy mondal

the output will be infinite no. of 5s ..bcoz integer a is
static its value wont b changed ever..

Is This Answer Correct ?    2 Yes 4 No

Post New Answer

More C Interview Questions

#include<stdio.h> #include<conio.h> void main() {clrscr(); char another='y'; int num; for(;another=='y';) { printf("Enter a number"); scanf("%d",&num); printf("squre of %d is %d",num,num*num); printf("\nwant to enter another number y/n"); scanf("%c",&another); } getch(); } the above code runs only one time.on entering 'y' the screen disappeares.what can i do?

3 Answers  


Are negative numbers true in c?

0 Answers  


What is the Difference between Macro and ordinary definition?

3 Answers   Bosch, Cognizant, College School Exams Tests, Motorola,


How to implement variable argument functions ?

1 Answers   HP,


what is ur strangth & weekness

0 Answers   Cognizant, LG Soft, NetEnrich,


What is 1f in c?

0 Answers  


print pattern 1 1 33 33 555 555 77777777 555 555 33 33 1 1

1 Answers   Winit,


Explain what is the best way to comment out a section of code that contains comments?

0 Answers  


Sir i want e-notes of C languge of BAlaguruswami book i.e scanned or pdf file of balaguruswamy book on c language.PLEASE SEND ME on my mail id ajit_kolhe@rediff.com

8 Answers  


Explain how do you convert strings to numbers in c?

0 Answers  


Can one function call another?

0 Answers  


general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only

0 Answers  


Categories