#weird assignment thing

13 messages · Page 1 of 1 (latest)

swift sparrow
#

Ive come across this code and i initally thought it was just wrong where the , was accidently used over the . but it compiles and produces a different results to 44.4. What is happening on that line?

void main()
{
    float promien, wysokosc, objetosc;
    float pi = 3.1415926;
    promien = 3.3;
    //
    wysokosc = 44,4;
    //
    objetosc = pi * promien * promien * wysokosc;
    printf("Objetosc walca to: %f", objetosc);
    getchar();
}
hallow jacinthBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

half cliffBOT
#
Program Output
Objetosc walca to: 1505.325439
hollow hill
#

wysokosc = 44,4 is actually using the comma operator, which has lower precedence than assignment so it's really assigning 44 to wysokosc

swift sparrow
#

so is that to say there's a random dangling 4 for no reason?

hollow hill
#

the 4 will be the result of the comma operator, which goes unused

#

so yes

#

if you removed the ,4 it would work the same way

swift sparrow
#

very weird

#

but makes sense

#

thanks

#

!solved