Follow us on Twitter!
Hacking isn't just Computers & Exploits. It's a Philosophy. - Mr_Cheese
Friday, April 25, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 26
Guests Online: 23
Members Online: 3

Registered Members: 82906
Newest Member: ilija
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

need help ... in c

the_unwanted
Member

Your avatar

Posts: 11
Location:
Joined: 03.12.10
Rank:
Newbie
Posted on 13-02-11 13:16
#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:
Newbie
Posted on 13-02-11 13:26
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
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 13-02-11 17:21
Because you're using printf wrong. You're supposed to pass an additional argument for each identifier in the format string.


halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg
ynori7 http://halls-of-valhalla.org
Author

RE: need help ... in c


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 13-02-11 20:47
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);



Author

RE: need help ... in c


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 13-02-11 21:09
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++



Author

RE: need help ... in c

ynori7
Member



Posts: 1486
Location: #valhalla
Joined: 08.10.07
Rank:
God
Posted on 13-02-11 21:12
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.


halls-of-valhalla.org/images/affiliateLogo.png voodoorage.halls-of-valhalla.org/images/smallLogo.png
i537.photobucket.com/albums/ff338/ynori77/archenemysig1.jpg
ynori7 http://halls-of-valhalla.org
Author

RE: need help ... in c

GTADarkDude
Member



Posts: 142
Location: The Netherlands
Joined: 23.02.08
Rank:
Newbie
Posted on 14-02-11 07:35
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. Pfft


...
- - -