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

In the following control structure which is faster? 1.Switch 2.If-else and which consumes more memory?

4 Answers  


i am using gsm modem ! I USE CMGL COMMAND TO DISPLAY THE LIST OF MESSAGES ! I WANT TO READ EACH MESSAGE ONE BY ONE AND GET EACH MESSAGE INDEX USING C PROGRAM ! THE RESPONSE OF THE MODULE AFTER AT+CMGL IS ---CMGL: 1,"REC READ","+85291234567",,"07/05/01,08:00:15+32",145,37 It is easy to list SMS text messages.---- I WANT THE PROGRAM TO GET THE NUMBER "37"{MESSAGE LENGTH} AS WELL AS "1"(MESSAGE INDEX NUMBER" PLEASE HELP

1 Answers   MTNL,


Write a program which take a integer from user and tell whether the given variable is squar of some number or not. eg: is this number is 1,4,9,16... or not

9 Answers   Alcatel,


how to write a program which adds two numbers without using semicolon in c

2 Answers  


Explain what is the difference between null and nul?

0 Answers  






write a program to find out number of on bits in a number?

17 Answers   Huawei, Microsoft,


What are the application of void data type in c?

0 Answers  


Implement a function that returns the 5th element from the end in a singly linked list of integers in one pass.

11 Answers   Microsoft,


What is the diffences between Windows XP and Windows Visa

1 Answers   Aricent, FHF,


consider the following program sigment int n,sum=1; switch(n) { case 2:sum=sum+2; case 3:sum*=2; break; default:sum=0;} if n=2, what is the value of sum a.0 b.6 c.3 d.none

7 Answers   TCS,


write a proram to reverse the string using switch case?

0 Answers   Syntel,


what is the little endian and big endian?

1 Answers  


Categories