Members Online
Total Online: 49 Web Spiders: 18
Guests Online: 43
Members Online: 6
Registered Members: 70203 Newest Member: monkiman
|
View Thread
| Author |
need help ... in c |
the_unwanted
Member
Posts: 11
Location:
Joined: 03.12.10 Rank: Newbie |
|
#include<stdio.h>
void main()
{
printf("%d,%d,%d,%d");
}
o/p on dev c++ is : 148,3806552,4199093,2293576
o/p on turbo c++ is : 0,344,0,0
question 1: why o/p vary( i mean why o/p is not same on both compilers)
question 2: im gettin same o/p in dev c++(148,3806552,4199093,2293576)
....i executed it number of times....i restarted and
executed again but o/p is same (148,3806552,4199093,2293576)
same thing is happening on turbo c++ compiler .. o/p is not changing (0,344,0,0)
edit: i know printf function prototype (printf("%d",a);//a variable) and i know that when using printf in this way printf("%d"); displays a value of random memory
but i wanted to know why compliers pickin same random memmories and displayin same value...i restared system and executed it again and o/p is same ....it means the way compliers picking random memories are not just coincidence ...its following a some constant pattren...
does any know why this happening??
does compliers really follow some constant pattren??
thank u all for ur replies
sorry for my bad english :(
Edited by the_unwanted on 14-02-11 10:16 |
|
| Author |
RE: need help ... in c |
GTADarkDude
Member

Posts: 142
Location: The Netherlands
Joined: 23.02.08 Rank: God |
|
You're outputting (kinda) random values from your memory. It seems that both compilers read from different memory locations right now. Apparently these values have not changed yet, or else rerunning the programs would indeed give you different results. But that's merely a coincidence, not something you can ever rely on.
EDIT: Wow, my hundredth post! And that in just under three years... ^^
...
Edited by GTADarkDude on 13-02-11 13:48 |
|
| Author |
RE: need help ... in c |
ynori7
Future Emperor of Earth

Posts: 1481
Location: #valhalla
Joined: 08.10.07 Rank: Diabolical |
|
Because you're using printf wrong. You're supposed to pass an additional argument for each identifier in the format string.
|
|
| Author |
RE: need help ... in c |
dieslow_13
Member

Posts: 9
Location: Behind Yer Back
Joined: 16.01.11 Rank: Wiseman |
|
well am not that good in C but i think there should be some changes if am correct
1- you should declare your variables which should be integers as you stated %d.
2- i think it should be
printf ("%d%d%d%d", variable1,variable2,variable3);
www.torn.com/1287944
willing to learn





|
|
| Author |
RE: need help ... in c |
dieslow_13
Member

Posts: 9
Location: Behind Yer Back
Joined: 16.01.11 Rank: Wiseman |
|
|
dieslow_13 wrote:
well am not that good in C but i think there should be some changes if am correct
1- you should declare your variables which should be integers as you stated %d.
2- i think it should be
printf ("%d%d%d%d", variable1,variable2,variable3);
and i was curious to try
#include <stdio.h>
main ()
{ int s,d,f;
printf ("%d\n%d\n%d",s,d,f);
return 0;
}
the result was
19125
9351
8653
using turbo c++
www.torn.com/1287944
willing to learn





|
|
| Author |
RE: need help ... in c |
ynori7
Future Emperor of Earth

Posts: 1481
Location: #valhalla
Joined: 08.10.07 Rank: Diabolical |
|
|
dieslow_13 wrote:
and i was curious to try
#include <stdio.h>
main ()
{ int s,d,f;
printf ("%d\n%d\n%d",s,d,f);
return 0;
}
the result was
19125
9351
8653
using turbo c++
Yeah, it's just grabbing whatever crap it finds in the four bytes at the location in memory where it expects an integer to be and prints it as a decimal value.
|
|
| Author |
RE: need help ... in c |
GTADarkDude
Member

Posts: 142
Location: The Netherlands
Joined: 23.02.08 Rank: God |
|
|
ynori7 wrote:
Because you're using printf wrong. You're supposed to pass an additional argument for each identifier in the format string.
I kinda assumed the OP knew that, I thought he was just messing around. If he did not know this, then it was an extraordinary stupid question.
... |
|
|
|
|