C Pointer problem

T

Tom St Denis

Frederick said:
Simon Biber posted:




Yes I am well aware of how C operator precedence works -- I was referring
to the way human beings do math.

On the European side of the Atlantic, we learn BOMDAS rather than BODMAS,
and this would lead us to interpret the following line differently:

4 * 12 / 3 * 8

That's the same as

4 * 12 * 1/3 * 8 == 128

Now had you wrote it as 4 * 12 / (3 * 8) then you'd have two.

That's like if you wrote

4 + 12 - 3 + 8

Does that mean

4 + 12 - (3 + 8) ?

No?

Then why does

4 * 12 / 3 * 8 mean 4*12/(3*8)?

.....

Tom
 
F

Frederick Gotham

Mark McIntyre posted:
Euh. only if you put in some brackets. I can't otherwise see how four
times twelve thirds times eight can equal two.

But then, everything *is* bigger in the States. :)


Should I wait for you to re-post acknowledging your mistake, or should I
post the solution now?


If we multiply first, we get:

4*12 divided by 3*8

which becomes:

48 divided by 24

which becomes:

2
 
T

Tom St Denis

Frederick said:
Should I wait for you to re-post acknowledging your mistake, or should I
post the solution now?


If we multiply first, we get:

4*12 divided by 3*8

But that isn't what you wrote. You wrote 4*12/3*8.
which becomes:

48 divided by 24

No that becomes 4*4*8.

Not only does logic dictate that but GNU BC, Perl and GCC all agree
that 4*12/3*8 is 128.

And the rule is BEDMAS not BODMAS which stands for Brackets, Exponents,
Division AND Multiplication, Addition AND Subtraction.

Note the use of AND.

By your logic 4+12-3+8 is 5.

Tom
 
R

Richard Tobin

Frederick Gotham said:
On the European side of the Atlantic, we learn BOMDAS rather than BODMAS,

Educational standards must have dropped since my day then.

There is no difference in precedence between multiplication and
division.

The same goes for addition and subtraction. Do you think that 3-2+1
is 0?

-- Richard
 
R

Richard Heathfield

Frederick Gotham said:
Simon Biber posted:




Yes I am well aware of how C operator precedence works -- I was referring
to the way human beings do math.

On the European side of the Atlantic, we learn BOMDAS rather than BODMAS,

Presumably that's on the European side of the English Channel, too. On the
/English/ side of the English Channel, I learned BODMAS at school, and my
children report that they, too, have learned BODMAS.
and this would lead us to interpret the following line differently:

4 * 12 / 3 * 8


C compiler interpretation: 128

American interpretation: 128

European interpretation: 2

English interpretation: Four lots of twelve and thruppence is two pounds
nine shillings; eight times that is nineteen pounds twelve, which is seven
quid for you and twelve guineas for me.
 
M

Michael Mair

Richard said:
Frederick Gotham said:

Presumably that's on the European side of the English Channel, too. On the
/English/ side of the English Channel, I learned BODMAS at school, and my
children report that they, too, have learned BODMAS.

I never learnt any BODMAS or BOMDAS -- I just learned the precedence
rules (as in "Punkt vor Strich" ;-)).
English interpretation: Four lots of twelve and thruppence is two pounds
nine shillings; eight times that is nineteen pounds twelve, which is seven
quid for you and twelve guineas for me.

Write one hundred times
"Decimalisation and Metric System are good for us,
we are looking forward to adopt whatever else Brussels
throws at us".
*g,d&r*


SCNR
Michael
 
R

Richard Tobin

Michael Mair said:
"Decimalisation and Metric System are good for us,
we are looking forward to adopt whatever else Brussels
throws at us".

Decimalisation was announced years before Britain negotiated entry to
the EEC. And metrication would have happened anyway.

Anyway, a rod-pole-or-perch can be approximated as 5m for most purposes.

-- Richard
 
K

Keith Thompson

Mark McIntyre said:
Euh. only if you put in some brackets. I can't otherwise see how four
times twelve thirds times eight can equal two.

But then, everything *is* bigger in the States. :)

It seems obvious to me that *if* "*" binds more tightly than "/", then
the above expression

4 * 12 / 3 * 8

is equivalent to

(4 * 12) / (3 * 8)

which evaluates to 2.

There's nothing inherently inconsistent about a system in which "*"
binds more tightly than "/", but I've never heard of one. Certainly
we're all in agreement that they have the same precedence in C; I've
never encountered any other programming language in which they have
different precedence. In ordinary arithmetic as I learned it, they
have the same precedence, and the expression evaluates to 128. It's
not inconceivable that they have different precedence in some parts of
Europe, but if so this is the first I've heard of it.

I *probably* wouldn't write an expression like that that mixes "*" and
"/"; I'd likely add parentheses or even rearrange the expression, not
because it's ambiguous but because it's not immediately obvious.

In hand-written arithmetic, division is commonly represented as a
horizontal line rather than as an operator, so precedence is
determined by the placement of the parts of the expression:

4 * 12
------ * 8
3

or

12
4 * -- * 8
4

which avoids any ambiguity in the first place.

(BTW, I never learned "BOMDAS" or "BODMAS"; I just learned the rules.)
 
F

Frederick Gotham

Richard Heathfield posted:

Presumably that's on the European side of the English Channel, too. On
the /English/ side of the English Channel, I learned BODMAS at school,
and my children report that they, too, have learned BODMAS.


I'm in Dublin in Ireland. I learned "BOMDAS" at school when I was either
ten or eleven, and that's only nine years ago -- but nevertheless, they may
have changed it in the meantime.
 
R

Richard Heathfield

Frederick Gotham said:
Richard Heathfield posted:




I'm in Dublin in Ireland. I learned "BOMDAS" at school when I was either
ten or eleven, and that's only nine years ago -- but nevertheless, they
may have changed it in the meantime.

Ah, my apologies. You're on the European side of the /Irish/ Channel. :)
 
G

Gordon Burditt

Someone tell me, does one learn PODMAS instead of BODMAS in the USA?
I actually learned BOMDAS at school, rather than "BODMAS".

Brackets
Off
Multiply
Divide
Add
Substract

Parentheses count. I always thought that math as well as FORTRAN
and C taught BO(MD)(AS), *not* BODMAS nor BOMDAS, unless division
was represented textually as a big horizontal bar with the denominator
being clearly distinguished by what was under the bar. But I was
educated on the USA side of the pond.

Gordon L. Burditt
 
G

goose

Mark said:
It was, obviously, contained within the brackets. -)


Two nations divided by a common language indeed.

For the record, brackets come in three flavours, square, wiggly and
plain.

4. angle <>

goose
 
P

pete

goose said:
4. angle <>

The standard doesn't give a name for <>,
but I also call them angle brackets.

I will always advocate using standard terminology,
when discussing what the C standard says.
 
W

Walter Roberson

Mark McIntyre wrote:
4. angle <>

I understand that in at least some parts of Europe (e.g., France), there
is also <<>> where << and >> are the closest easy representation
to single characters smaller and raised to be centred on the line.
I have, though, not encountered this enough to be sure whether they
are used as brackets or only as a form of quotation -- I -think- I've
seen both uses.
 
K

Keith Thompson

Mark McIntyre said:
Two nations divided by a common language indeed.

For the record, brackets come in three flavours, square, wiggly and
plain.

gd&r

Does British English not commonly use the terms "parentheses" and
"braces"?

I understand that "braces" refers to the clothing accessory that
Americans refer to as "suspenders", but there seems to be little
chance of confusion.
 
I

Ian Collins

Keith said:
Does British English not commonly use the terms "parentheses" and
"braces"?
Not in normal speech, "brackets" and "curly brackets" would be more common.
I understand that "braces" refers to the clothing accessory that
Americans refer to as "suspenders", but there seems to be little
chance of confusion.
"suspenders" hold up women's stockings, so talk of a man in suspenders
can cause all sorts of confusion!

The joys of a common language..
 
F

Flash Gordon

Keith said:
Does British English not commonly use the terms "parentheses" and
"braces"?

Parentheses was used in my maths class as school in Britain oh so many
years ago and we were told that it, and not brackets, was the correct
term for (). However, it was certainly common back then for people to
describe () as brackets.

So I, born and brought up in England, am happy with the terms
parenthesis (), brackets [] and braces {} but can also accept and cope
with round brackets, square brackets and squiggly brackets. I'll also
accept brackets for () without comment if the context removes any ambiguity.
I understand that "braces" refers to the clothing accessory that
Americans refer to as "suspenders", but there seems to be little
chance of confusion.

Yes, this is also true. Assuming, of course, that Americans common call
braces suspenders. However, you should possibly be aware that in Britain
suspenders are used by ladies to hold their stockings up, so be careful
what you ask for in a clothing store in Britain ;-)
 
C

Chris Dollin

Tom said:
But that isn't what you wrote. You wrote 4*12/3*8.


No that becomes 4*4*8.

Which part of "if we multiply first" escaped you?
Not only does logic dictate that

Logic doesn't have a say in it. Operator precedence is about convenient
convention.
 
R

Richard Bos

Ian Collins said:
Not in normal speech, "brackets" and "curly brackets" would be more common.

Probably because strictly speaking the parenthesis is the phrase
inserted into the surrounding sentence, nor either of the marks
delimiting it.
"suspenders" hold up women's stockings, so talk of a man in suspenders
can cause all sorts of confusion!

Unless, of course, said man wants to be a lumberjack.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top