I need some Simple C answers 
Author Message
 I need some Simple C answers

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?

2) what does DoublePlus ++ mean?

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?)

4) what does DoubleBar(pipe) lines || mean?

5) does /= mean Not Equal To?

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!



Wed, 28 Feb 2001 03:00:00 GMT  
 I need some Simple C answers


Quote:
>Questions are:

>1) What does PlusEqual += mean?

example: a += b means  a = a+b
Quote:

>2) what does DoublePlus ++ mean?

example:
        x++ means give me the value of x and then increment x
        ++x means indrement x, then give me the new value
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?)

the ;  ends a C statement.

Quote:

>4) what does DoubleBar(pipe) lines || mean?

a || b performs the logical OR of a and b

Quote:

>5) does /= mean Not Equal To?

example: a /= b means a = a / b (/ is the divide operator)
this is similar to #1, and can also be done with - and *.

/RF
Robert Fries
rfries at pacbell dot net



Wed, 28 Feb 2001 03:00:00 GMT  
 I need some Simple C answers

Quote:
>>1) What does PlusEqual += mean?
>example: a += b means  a = a+b

>>2) what does DoublePlus ++ mean?
>example:
>>5) does /= mean Not Equal To?

>example: a /= b means a = a / b     (/ is the divide operator)
>this is similar to #1, and can also be done with - and *.

Most excellent!  THANKS Robert!

 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!



Wed, 28 Feb 2001 03:00:00 GMT  
 I need some Simple C answers

Quote:

> 1) What does PlusEqual += mean?

It's a shorthand notation.

   a += b;

is equivalent to

   a = a + b;

Quote:
> 2) what does DoublePlus ++ mean?

Add one.  It can be placed either in front of or after the value being
incremented, the difference being when the increment occurs (not that
this makes any difference in the example you posted).  

When used in an expression ++a means "increment a, yielding the new
value" while "a++" means "yield the current value of a, then sometime
before the end of the expression increment 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?)

The ; is being used to mark the end of a statement.  In C it is
possible to write something like

   a = 4; b = 5; c = 6;

or (if you really want to)

   a
   =
   4
   ;

and so on.

Quote:
> 4) what does DoubleBar(pipe) lines || mean?

Logical or.

Quote:
> 5) does /= mean Not Equal To?

Not in C.  As for +=, it's a shorthand with

   a /= b;

being equivalent to

   a = a / b;

Substraction and division have the obvious equivalents.

--

            http://www.tardis.ed.ac.uk/~broonie/
EUFS        http://www.eusa.ed.ac.uk/societies/filmsoc/



Wed, 28 Feb 2001 03:00:00 GMT  
 I need some Simple C answers
robert fries wrote in a message to All:

Quote:
>1) What does PlusEqual += mean?

 rf> example: a += b means  a = a+b
<snip>
Quote:
>5) does /= mean Not Equal To?

 rf> example: a /= b means a = a / b   (/ is the divide operator) this
 rf> is similar to #1, and can also be done with - and *.

Not to forget %, &, ^, |, << and >>.

greetings,
Tom



Wed, 28 Feb 2001 03:00:00 GMT  
 I need some Simple C answers

Quote:

>>5) does /= mean Not Equal To?
> rf> example: a /= b means a = a / b   (/ is the divide operator)

The Not Equal operator in C is
   !=
For example...
   if (a != b)
      printf("a is not equal to b.   \n");
   else
      printf("a and b are the same.   \n");

To go off at a (minor) tangent, now that my mind's on it...
When C was being designed, why did they use = to represent the asignment
operator, and not := (as in Pascal)?
Then, for equality, they could have used = (seems better mathematically) or
== (as they do now, and would avoid confusion from ex-BASIC programmers over
percieved similarities between the use of the = symbol in both languages).
If they'd done this, it would also have been wise to change the not-equal
operator from != to <> , as I feel != might be too similar to := in ceratin
fonts(?).

Just a thought. Don't think for a minute I'd seriously propose changing
something that fundamental after almost 30 years!!....


  (Remove "BYEPSAM" spam filter when replying by mail)



Wed, 28 Feb 2001 03:00:00 GMT  
 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".

- Show quoted text -

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!



Wed, 28 Feb 2001 03:00:00 GMT  
 I need some Simple C answers

   To go off at a (minor) tangent, now that my mind's on it...
   When C was being designed, why did they use = to represent the asignment
   operator, and not := (as in Pascal)?

If you want Pascal, you know where to get it.

   Then, for equality, they could have used = (seems better mathematically) or
   == (as they do now, and would avoid confusion from ex-BASIC programmers over
   percieved similarities between the use of the = symbol in both languages).

If you want BASIC, you know where to get it.

   If they'd done this, it would also have been wise to change the not-equal
   operator from != to <> , as I feel != might be too similar to := in ceratin
   fonts(?).

   Just a thought. Don't think for a minute I'd seriously propose changing
   something that fundamental after almost 30 years!!....

(Oh, thank God.  He's not serious.)
--
(supporter of the campaign for grumpiness where grumpiness is due in c.l.c)

Please: do not email me copies of your posts to comp.lang.c
        do not ask me C questions via email; post them instead



Wed, 28 Feb 2001 03:00:00 GMT  
 I need some Simple C answers
[...]
: To go off at a (minor) tangent, now that my mind's on it...
: When C was being designed, why did they use = to represent the asignment
: operator, and not := (as in Pascal)?
: Then, for equality, they could have used = (seems better mathematically) or
: == (as they do now, and would avoid confusion from ex-BASIC programmers over
: percieved similarities between the use of the = symbol in both languages).
: If they'd done this, it would also have been wise to change the not-equal
: operator from != to <> , as I feel != might be too similar to := in ceratin
: fonts(?).

BCPL uses ':=' for assignment, '=' for equality and initialisation,
and ~=, >=, <= for the other booleans.  C seems to have copied most
of BCPL's operators apart from assignment (tho' of course arrays/
dereferencing is very different).

Will



Thu, 01 Mar 2001 03:00:00 GMT  
 I need some Simple C answers

Quote:


>    To go off at a (minor) tangent, now that my mind's on it...
>    When C was being designed, why did they use = to represent the asignment
>    operator, and not := (as in Pascal)?

> If you want Pascal, you know where to get it.

And this answers the question exactly how?  It's a legitimate question,
although I have no idea what the true answer is.

Quote:
>    Then, for equality, they could have used = (seems better mathematically) or
>    == (as they do now, and would avoid confusion from ex-BASIC
programmers over
>    percieved similarities between the use of the = symbol in both languages).

> If you want BASIC, you know where to get it.

More importantly, using := for assignment and == for testing equality would
help eliminate that most common of typos,

   if (a = b) {...}

since '=' would not be a legal token.  

Quote:
>    If they'd done this, it would also have been wise to change the not-equal
>    operator from != to <> , as I feel != might be too similar to := in ceratin
>    fonts(?).

Ah.  So we introduce a new typo,

   a := b != c;      /* assign 1 to a if b not equal to c */

instead of

   a := b := c;     /* assign value of c to b and a */

Quote:
>    Just a thought. Don't think for a minute I'd seriously propose changing
>    something that fundamental after almost 30 years!!....

> (Oh, thank God.  He's not serious.)

And another thing -- enough with the language snobbery!  If it gets the job
done with the minimum amount of pain, what's the problem?  Granted, I don't
want to be stuck doing Visual Basic for the rest of my life, but that has
more to do with the types of projects VB is suited for than the language
itself.

Quote:
> --
> (supporter of the campaign for grumpiness where grumpiness is due in c.l.c)

> Please: do not email me copies of your posts to comp.lang.c
>         do not ask me C questions via email; post them instead

--
John Bode
one grumpy code monkey

  A Programmer writes code that will run at the end of the day.
  A Software Engineer writes code that will run ten years from now.

To email me directly, remove the 'nospam.' from my address.



Thu, 01 Mar 2001 03:00:00 GMT  
 
 [ 28 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Simple problem across processes - need simplest answer

2. Help... V Simple Questions Need Answering

3. Need answer for probably very simple question...

4. Newbie: separate big .cs file into small .cs files

5. newbe/cs student, need help w/ code

6. resx files needed for cs - files ??

7. Need C++ text for non cs major course

8. A simple question, but still no answer

9. simple question, pls answer\

10. Simple question ( for those how knows the answer )

11. This question must have a simple answer.

12. May your your simple C answer!

 

 
Powered by phpBB® Forum Software