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

what is difference b/w extern & volatile variable??

6 Answers   Teleca,


What is the symbol indicated the c-preprocessor?

0 Answers  


How do shell structures work?

0 Answers  


how to write optimum code to divide a 50 digit number with a 25 digit number??

0 Answers   MGM,


What are the types of i/o functions?

0 Answers  






how to construct a simulator keeping the logical boolean gates in c

0 Answers  


Why the use of alloca() is discouraged?

2 Answers   Oracle,


Write c-code for 5+55+555+5555+55555+555555+5555555. Output will be it's answer...

4 Answers   TCS,


If jack lies on Mon, Tue Wed and jill lies on Thursday, Friday and Saturday. If both together tell they lied yesterday. So c the given options and then c cos in the given dates one will be saying the truth and one will be lying. I got Thursday as option because jack is saying the truth he lied yest but jill is lying again as he lies on that day.

0 Answers   TCS,


What is the difference between malloc calloc and realloc in c?

0 Answers  


Explain argument and its types.

0 Answers  


What is structure padding & expalain wid example what is bit wise structure?

1 Answers  


Categories