Hello guyz
here is a sample code in C with output but i coudnt undrstnd the reason for output values...... please explain it if any1 knw....
main()
{
printf("%d %d %d %d");
}
o/p-- 0 344 0 0
Hello guyz
here is a sample code in C with output but i coudnt undrstnd the reason for output values...... please explain it if any1 knw....
main()
{
printf("%d %d %d %d");
}
o/p-- 0 344 0 0
printf doesn't actually know how many parameters you give it, it examines the string and assumes you provided that many variables, because you did not, it prints out garbage leftover in memory from another program
╔╗╔══╦╗
║║║╔╗║║
║╚╣╚╝║╚╗
╚═╩══╩═╝
Yeah.
You would want to use it like:
Note: Most strings are either prefixed or sufixed with a new line characters ("\n") - so you would have something like:Code:printf("%d %d %d %d", 10, 20, 30, 40); Printing: 10 20 30 40 or printf("Number %d has a name of %s and an age of %d.", 375, "Sam", 17); Printing: Number 375 has a name of Sam and an age of 17.
If you don't, it'll all print on the same line, soft wrapping at the end of the terminal.Code:printf("Hello world\n");
synadacate
i understood wt u said.... n i knw it..... bt here the prob is little bit different.....
Originally Posted by ಠ_ಠ
printf doesn't actually know how many parameters you give it, it examines the string and assumes you provided that many variables, because you did not, it prints out garbage leftover in memory from another program
these are not the garbage values.... coz on every computer the values are same.
> these are not the garbage values.... coz on every computer the values are same.
YouŽre confusing repeatability with being correct.
The local memory layout of the stack frame for any given run of your program generated by a single compiler will likely be constant. The fact that it seems the same doesnŽt make it any less uninitialised as far as youŽre concerned.
Try it with a different compiler, youŽll get different answers (ALL of them wrong).
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
salem
thnx..... ya iknw... on diff. compilers the result wl b diff.
r u sure dat da same compiler cn give same rslt on evry computer..... n da rslt is nt machine dependent?
There are garbage; most likely from your own program.
If you used a different Compiler they might change or a different OS.
I would have guess all zeros as the most likely values to happen for an compiler not displaying garbage values. One of yours was not zero.
Tim S.
stahta01
yeah.... m jst thinking.....y the second value is not 0?
You know what else is garbage? The crappy SMS-speak you're spewing through your keyboard. SPEAK PROPER ENGLISH!
You haven't specified any values to print, so printf just made up some.
This HAS been tried. Inspired by the monkey with his mouth covered in a mythological tale.reason for output in C
But it failed, badly - I think it was the marketing, that killed it. Who's going to buy a "C-Dumb" compiler?
You see the problem? Unless you're the guy with his eye's covered.
<ROFL>
Last edited by Adak; 10-07-2010 at 05:58 AM.
Well after the latest keyboard dribble, I lost interest.
How To Ask Questions The Smart Way
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.