• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

operators assignment.....????

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Look carefully! You might be tempted to think the output is b is false
but look at the boolean test in line 12. The boolean variable b is not being compared to
true, it's being set to true, so the println executes and we get b is true . The result
of any assignment expression is the value of the variable following the assignment. This
substitution of = for == works only with boolean variables, since the if test can be done
only on boolean expressions. Thus, this does not compile:

Because x is an integer (and not a boolean), the result of (x = 0) is 0
(the result of the assignment). Primitive ints cannot be used where a boolean value is
expected, so the code in line 8 won't work unless changed from an assignment (=) to an
equality test (==) as follows:



please expalin this line"The result
of any assignment expression is the value of the variable following the assignment"..... i am somehow confused with this line....
 
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hennry Smith wrote:
Look carefully! You might be tempted to think the output is b is false
but look at the boolean test in line 12. The boolean variable b is not being compared to
true, it's being set to true, so the println executes and we get b is true . The result
of any assignment expression is the value of the variable following the assignment. This
substitution of = for == works only with boolean variables, since the if test can be done
only on boolean expressions. Thus, this does not compile:

Because x is an integer (and not a boolean), the result of (x = 0) is 0
(the result of the assignment). Primitive ints cannot be used where a boolean value is
expected, so the code in line 8 won't work unless changed from an assignment (=) to an
equality test (==) as follows:



please expalin this line"The result
of any assignment expression is the value of the variable following the assignment"..... i am somehow confused with this line....


Hi Henry...
First things first let us simply find out what an assignment expression is...
My 'logical understanding' is as follows.

1. a = b // is an assignment expression. That simply says "a is b" or "please refer a to the value of b"

2. lets assume that the value of b is 10.

3. if b is 10 it means that a is 10!, since "a is b".

I hope this helps.



3.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



assignment operator means "="
assignment expression means b=true
The output of b=true ( assignment expression ) is the value of the b ( variable ).
 
Don't destroy the earth! That's where I keep all my stuff! Including this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic