recursive main

R

rahul8143

hello,
I have another problem in static variables. See following code
why it prints all 0 instead 4 3 2 1 ?
1)
void main()
{
static int i=5;
if(--i){
main();
printf("%d ",i);
}
}
Answer:
0 0 0 0
 
D

DevarajA

(e-mail address removed) ha scritto:
hello,
I have another problem in static variables. See following code
why it prints all 0 instead 4 3 2 1 ?
1)
void main()
{
static int i=5;
if(--i){
main();
printf("%d ",i);

You must print before calling main again.
 
M

Martin Ambuhl

hello,
I have another problem in static variables. See following code
why it prints all 0 instead 4 3 2 1 ?
1)
void main()
^^^
How can anyone have the gall to post three questions all with the same
basic error?
 
J

Johan Borkhuis

Martin said:
^^^
How can anyone have the gall to post three questions all with the same
basic error?

At least he is consistent..........

Kind regards,
Johan

--
o o o o o o o . . . _____J_o_h_a_n___B_o_r_k_h_u_i_s___
o _____ || http://www.borkhuis.com |
.][__n_n_|DD[ ====_____ | (e-mail address removed) |
>(________|__|_[_________]_|________________________________|
_/oo OOOOO oo` ooo ooo 'o!o!o o!o!o`
== VxWorks FAQ: http://www.xs4all.nl/~borkhuis/vxworks/vxworks.html ==
 
F

Fao, Sean

Here's another one for you. Predict the outcome of this program without
running it:

<code>
#include <stdio.h>

int main(void)
{
static int i = 5;

if (--i)
{
printf("%d ", i);
main();
}

putchar('\n');

return 0;
}
</code>

For even more points, explain why.
 
E

Emmanuel Delahaye

what is mean by PDNFTT??

Now, I know!

_____________________
/| /| | |
||__|| | Please do not |
/ O O\__ | feed the |
/ \ | Trolls |
/ \ \|_____________________|
/ _ \ \ ||
/ |\____\ \ ||
/ | | | |\____/ ||
/ \|_|_|/ | _||
/ / \ |____| ||
/ | | | --|
| | | |____ --|
* _ | |_|_|_| | \-/
*-- _--\ _ \ | ||
/ _ \\ | / `
* / \_ /- | | |
* ___ c_c_c_C/ \C_c_c_c____________



--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"It's specified. But anyone who writes code like that should be
transmogrified into earthworms and fed to ducks." -- Chris Dollin CLC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top