need help ... in c
#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 :(
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… ^^
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++
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.