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

Why enum is used in c?

0 Answers  


What is build process in c?

0 Answers  


find a number whether it is even or odd without using any control structures and relational operators?

22 Answers   Microsoft, Shashank Private Limited,


How many keywords (reserve words) are in c?

0 Answers  


A float occupies 4 bytes in memory. How many bits are used to store exponent part? since we can have up to 38 number for exponent so 2 ki power 6 6, 6 bits will be used. If 6 bits are used why do not we have up to 64 numbers in exponent?

0 Answers  






What is getch () for?

0 Answers  


What is static identifier?

0 Answers   TCS,


what are the general concepts of c and c++

2 Answers  


What is the scope of static variable in c?

0 Answers  


write a c program to find the square of a 5 digit number and print the result.

5 Answers   Accenture, Sasken, Vimukti Technologies,


how to print this sereis 2 4 3 6 5..........?

3 Answers  


a value that does not change during program execution a) variabe b) argument c) parameter d) none

0 Answers  


Categories