printf returning values problem

This is a discussion on printf returning values problem within the C Programming forums, part of the General Programming Boards category; righto then. Cheers for all the comments I understand the junk variable thing alot better now....

  1. #16
    Registered User
    Join Date
    Mar 2005
    Posts
    14
    righto then.
    Cheers for all the comments I understand the junk variable thing alot better now.

  2. #17
    Registered User
    Join Date
    Mar 2005
    Posts
    36
    Actually, the area was probably initialized to nulls by the OS or the OS's loader. Then the stack was used by the c-program starter module which was linked into your (every) program by the compiler, which called main(). In this case, the data accessed is on the stack for the call to main(). It may very well stay the same until you change or upgrade your compiler or OS, or maybe even then. If not in main(), or even with args to main listed, the likelihood of repeatability is much much smaller. However if you got 2 for your prog, then this code probably gives 2, 6, largenumber, 0, 15, another large number. (gcc w/XP)
    Code:
    #include<stdio.h>
    main() 
    {   
    int a;
    int b;
    int c;
    int d;
    int e;
    int f;
    printf("a is %d \n",a);
    printf("b is %d \n",b);
    printf("c is %d \n",c);
    printf("d is %d \n",d);
    printf("e is %d \n",e);
    printf("f is %d \n",f);
    
    getch();
    }
    If this is so, you can probably use the whole alphabet and get pretty stable answers. The reason is that your OS is setting you up in a virtual partition cleared to nulls and your program starts at the same (virtual) address each time, with almost nothing but the loading and starting code running in it first.

  3. #18
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You can of course completely ignore people who have no idea what they're talking about and are just talking out their asses.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #19
    ---
    Join Date
    May 2004
    Posts
    1,379
    Quote Originally Posted by Karthur
    Actually, the area was probably initialized to nulls by the OS or the OS's loader. Then the stack was used by the c-program starter module which was linked into your (every) program by the compiler...
    This dribble is coming from someone who does not indent their code, does not use 'int main(void)' and uses undefined and non standard functions.

  5. #20
    Learn from the llama Marlon's Avatar
    Join Date
    Jun 2005
    Location
    South africa
    Posts
    25
    Oh sorry my mistake, so no values are given, its simply the last value in the memory section that is displayed. Now i also understand that better
    \
    Thanks
    `Who are YOU?' said the Caterpillar.
    This was not an encouraging opening for a conversation. Alice replied, rather shyly, `I--I hardly know, sir, just at present-- at least I know who I WAS when I got up this morning, but I think I must have been changed several times since then.' - Lewis Caroll's Alice in Wonderland.

  6. #21
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Quote Originally Posted by quzah
    You can of course completely ignore people who have no idea what they're talking about and are just talking out their asses.
    Quote Originally Posted by sand_man
    This dribble is coming from someone who does not indent their code, does not use 'int main(void)' and uses undefined and non standard functions.
    Karthur's post seemed substantially correct to me. Could you outline your issues with it (assuming quzah was referring to Karthur's post)?

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. menu problem!!! need U R G E N T help!!!
    By catcat28 in forum C Programming
    Replies: 16
    Last Post: 11-19-2007, 01:32 PM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  4. Whats Wrong Whith This!?
    By SmokingMonkey in forum C++ Programming
    Replies: 8
    Last Post: 06-01-2003, 10:42 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21