On Sat, 13 Oct 2007 02:37:26 -0000, MJK <ja*******@gmail.comwrote in
comp.lang.c++:
On Oct 12, 10:24 pm, Kenneth Porter <shiva.blackl...@sewingwitch.com>
wrote:
MJK <jafari...@gmail.comwrote in news:1192241830.668389.300410
@e34g2000pro.googlegroups.com:
Why the following program does not print any output?
Please leave enough context for somebody to understand what you are
talking about without having to read other posts.
Here is the original program you posted:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int i,j;
i=1000;
j=i*i;
printf("%d %d\n",i,j);
printf("TEST\n");
return(0);
}
Now back to your quoting of Kenneth's reply to your original post:
What environment? Where is stdout pointing?
Hello,
I am running it on LINUX.
Program is working when 'i' is small but when 'i' is bigger than
'100,000' the result is incorrect!
when i=100,000 then j which is j=i*i is equal to j=1410065408
Why don't you post a correct question? You originally posted, your
exact words, that the program "does not print any output."
Now you are telling us it DOES produce an output, completely different
from your original post. Now you are telling us that sometimes it
produces what you think is the correct output, and sometimes it
produces what you think is incorrect output.
Actually, the output is never incorrect, because the cases that you
think are incorrect involve undefined behavior, where there is no
correct or incorrect result.
The undefined behavior is caused by arithmetic overflow on a signed
int.
Compile and execute this program:
#include <stdio.h>
#include <limits.h>
int main(void)
{
printf("The maximum value of an int is %d\n", INT_MAX);
return 0;
}
Note the output.
Then use a calculator or pencil and paper and calculate the value of
100,000 times 100,000.
Compare the result of the calculation with the output of the program
above.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html