Welcome to HBH! If you had an account on hellboundhacker.org you will need to reset your password using the Lost Password system before you will be able to login.

need help ... in c


the_unwanted's Avatar
Member
0 0

#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 :(


GTADarkDude's Avatar
Member
0 0

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… ^^


ynori7's Avatar
Future Emperor of Earth
0 0

Because you're using printf wrong. You're supposed to pass an additional argument for each identifier in the format string.


ghost's Avatar
0 0

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);


ghost's Avatar
0 0

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++


ynori7's Avatar
Future Emperor of Earth
0 0

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.


GTADarkDude's Avatar
Member
0 0

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. :P