Hi all,
1)I am planning to use Pelles C to learn C.So I have a bunch of example programs I want to try out. I have created a project,and keep deleting the previous .C file and adding the new .C file,to compile and execute each example in turn.Is there a better way to do it?
Well, maybe. If you are playing with a lot of small examples (about a screen page or less), than this is certainly one way to do it.
For longer things, and examples that contain more than one file, creating a new project for each example is IMHO the better way though...
2)This snippet :
e=(d*c); // 102 float arithmetic
printf("\n e is %f",e);
prints 101.99998,instead of 102.Is there any reason for this?
Yes. Actually there are even two reasons for that.
1) floating point arithmetic is always subject to inaccuracies. As we don't know in your snippet how
c,
d and
e are defined and how
d and
c get their values, a deviation from the the resulting value that you assume is to be expected. That's true for pretty much any language/compiler that does not use BCD variables/arithmetic, as for most floating point values, there is no exact representation with the available bits for the mantissa.
2) You did not specify the output mask/accuracy for the
%f specifier, hence the program will use the default value which seems to be the same as "
%.5f", meaning 5 digits after the decimal point
3) sizeof(int),sizeof(float) both give 4bytes.Is this OK ?I thought float would be 8bytes wide.
Nope. Not sure what led you to assume this but
float is synonym with
single and is hence a 32bit value. To get a 64bit value, you have to explicitly use
double...
Ralf