Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Sybex 1Z0-815, Chapter 3, Review Question #20, Page 111

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
 in question #20 of Chapter 3, page 111, option A (Unary operators are always executed before any surrounding binary or ternary operators) is marked as correct. It`s true that unary operators have precedence over the others, but they are not ALWAYS executed before the others.
In case there are parentheses this is no longer the case. Or am I missing something?

Thank you very much,

Cheers,
Ilenia
 
Marshal
Posts: 68908
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

That answer is obviously to be taken in the context of the question in the book. Remember that the principal rule about execution order is left to right, but that takes precedences, associativity and () into consideration.
 
Rancher
Posts: 3599
38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ilenia Salvadori wrote:Hi,
 in question #20 of Chapter 3, page 111, option A (Unary operators are always executed before any surrounding binary or ternary operators) is marked as correct. It`s true that unary operators have precedence over the others, but they are not ALWAYS executed before the others.
In case there are parentheses this is no longer the case. Or am I missing something?



Hi !

I think you're right, it looks for me (I don't have the book) as an error.
However, I would like to show you a better example -- no parentheses involved:



prints:



so, the precedence of unary operators is not always regarding surrounding operations (unless I miss context of the book !)

MZ
 
please buy this thing and then I get a fat cut of the action:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic