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 the use of function overloading in C?

0 Answers   Ittiam Systems,


There is a mobile keypad with numbers 0-9 and alphabets on it. take input of 7 keys and then form a word from the alphabets present on those keys.

0 Answers  


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

0 Answers   L&T,


Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

0 Answers   Huawei,


Which is the best sort method for library management?

1 Answers   Microsoft,






why we use pointer in c

7 Answers   HCL, TCS,


Can we assign integer value to char in c?

0 Answers  


Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].

0 Answers  


what is the use of fflush() function?

2 Answers  


where are auto variables stored? What are the characteristics of an auto variable?

0 Answers  


Explain the advantages and disadvantages of macros.

0 Answers   TCS,


Which node is more powerful and can handle local information processing or graphics processing?

0 Answers  


Categories