
I need some Simple C answers
Quote:
> I'm writting a VB5 application (I 'know' this is a C newsgroup). My problem
> is that there is some mathimatical formulas that I need to use. I have some C
> code which contains this information.
> Now my knowledge of C is limited and I don't have any books on the language.
> Thus all I am looking for is some information on WHAT some parts of the code
> mean. Here are some parts of the code which has some of my questions:
> for (n = 0; n < IE_VERT_FLUX / 2; n++)
> phi_d += (double) pcalc->flux(n);
> .......
> if (p1 > 0.999 || p2 > 0.999 || p3 > 0.999)
> return (0.0);
> .......
> phi_d /= (double) pcalc->total_lm;
> Questions are:
> 1) What does PlusEqual += mean?
This is one of C's shorthand operators. In BASIC if you want to add 2 to a
variable named X you have to write "X = X + 2". In C you can write it the
same way, but you could also use the shorter "X += 2" which does the same
thing.
Quote:
> 2) what does DoublePlus ++ mean?
This is another of C's shorthand operators. It is very common in computer
programs to be adding or subtracting 1 from values. C provides four shorthand
methods for this. The C expression "X++" means the same as (C only) "X += 1"
or (C or BASIC) "X = X + 1", So does ++X. In the case the "n++" in your code
sample, both forms are exactly the same. If you use the value of the
expression it makes a difference whether the plus signs come before or after
the variable name.
int x = 3, y = 3;
x++; /* x is now 4 */
++y; /* y is now 4 */
Here is where there is a difference:
int x = 3, y = 3;
int a, b;
a = ++x; /* a = 4 and x = 4, 1 is added to x before */
/* assignment to a */
b = y++; /* b = 3 and y = 4, 1 is added to y after */
/* current value is assigned to a */
Quote:
> 3) is the ; at the end of the line of some meaning? This is on alot of lines
> and doesn't appear to be anything other than a way to break up long lines of
> code (true?)
Not true. In C every statement must be terminated with a semicolon. C is
less line oriented than true BASIC, and probably even
Visual Basic. White
space is not significant to C. A single statement can be written on several
physical lines, and more than one statement can be written on a single line.
This statement from your sample code:
phi_d += (double) pcalc->flux(n);
could also be written as:
phi_d
+=
(double)
pcalc->flux
(n)
;
The ";" ends the statement.
Quote:
> 4) what does DoubleBar(pipe) lines || mean?
This is logical OR operator in C.
The rough equivalent of BASIC's
IF X < 1 OR X > 10
is this in C:
if (x < 1 || x > 10)
And in case you come across it, && is the logical AND operator in C.
Quote:
> 5) does /= mean Not Equal To?
No, this is another shorthand operator. x /= 10 means "x = x / 10".
Quote:
> I greatly appreciate any answers!
> Regards,
> Bruce
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> No one is listening until you make a mistake!
> (live from the West End of Vancouver, B.C. Canada)
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> NOTICE: Please CHANGE my address of <NETCA.COM> to <NETCOM.CA> IF you
> ~~~~~~~ send me ANY Email replies. This was done to STOP all UnSolicted
> ~~~~~~~ JUNK E-Mailings. Sorry to do this BUT it does stop SPAM Email!