recursive main

Discussion in 'C Programming' started by rahul8143@gmail.com, Aug 5, 2005.

  1. Guest

    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
     
    , Aug 5, 2005
    #1
    1. Advertising

  2. DevarajA Guest

    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.

    --
    Devaraja (Xdevaraja87^gmail^c0mX)
    Linux Registerd User #338167
    http://counter.li.org
     
    DevarajA, Aug 5, 2005
    #2
    1. Advertising

  3. wrote:
    > 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?
     
    Martin Ambuhl, Aug 5, 2005
    #3
  4. Martin Ambuhl wrote:
    > wrote:
    >
    >> 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?


    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[ ====_____ | |
    >(________|__|_[_________]_|________________________________|

    _/oo OOOOO oo` ooo ooo 'o!o!o o!o!o`
    == VxWorks FAQ: http://www.xs4all.nl/~borkhuis/vxworks/vxworks.html ==
     
    Johan Borkhuis, Aug 5, 2005
    #4
  5. In article <J4FIe.48165$>,
    DevarajA <> wrote:
    > 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.


    PDNFTT
     
    Kenny McCormack, Aug 5, 2005
    #5
  6. In article <w8GIe.993$>,
    Martin Ambuhl <> wrote:
    > wrote:
    >> 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?


    PDNFTT
     
    Kenny McCormack, Aug 5, 2005
    #6
  7. Guest

    Kenny McCormack wrote:
    > In article <J4FIe.48165$>,
    > DevarajA <> wrote:
    > > 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.

    >
    > PDNFTT


    what is mean by PDNFTT??
     
    , Aug 5, 2005
    #7
  8. Guest

    Kenny McCormack wrote:
    > In article <J4FIe.48165$>,
    > DevarajA <> wrote:
    > > 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.

    >
    > PDNFTT


    what is mean by PDNFTT??
     
    , Aug 5, 2005
    #8
  9. Fao, Sean Guest

    wrote:
    > Kenny McCormack wrote:
    >PDNFTT
    >
    > what is mean by PDNFTT??
    >


    Please do not feed the trolls.
     
    Fao, Sean, Aug 5, 2005
    #9
  10. Fao, Sean Guest

    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.

    --
    Sean
     
    Fao, Sean, Aug 5, 2005
    #10
  11. wrote on 05/08/05 :
    >> PDNFTT

    >
    > 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
     
    Emmanuel Delahaye, Aug 6, 2005
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John M
    Replies:
    1
    Views:
    1,239
    Kumar Reddi
    May 29, 2005
  2. Seong-Kook Shin

    Q: recursive call to main, termination of program

    Seong-Kook Shin, Jan 26, 2005, in forum: C Programming
    Replies:
    5
    Views:
    406
    Koollman
    Jan 27, 2005
  3. n00m
    Replies:
    12
    Views:
    1,122
  4. vamsi
    Replies:
    21
    Views:
    2,114
    Keith Thompson
    Mar 9, 2009
  5. Yohan N. Leder
    Replies:
    19
    Views:
    254
    Yohan N. Leder
    Jul 2, 2006
Loading...

Share This Page