Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

K&B Practice Exam Question - Logical Operators

 
Brian Brumpton
Ranch Hand
Posts: 40
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 12 on practice exam 1 states:

Given:



What is the result?

I wrote down on my scratch paper 4 and then switched my answer to 6. I understand how the operator works, what I'm not 100% on is how/when x is incremented in this code?

on a side note: The explanation states "...an ! in front of an expression reserves its value." I'm pretty sure they mean reverses.
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I'm not gonna list out step by step.

For post/pre-increment and decrement, just remember this:
post-increment/decrement is assign then increment/decrement
pre-increment/decrement is increment/decrement then assign


 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Brumpton wrote:I understand how the operator works, what I'm not 100% on is how/when x is incremented in this code?

You can always tweak the program a little bit and add a print-method which shows when x is incremented Output:
1->2
3->3
4->4
4


Hope it helps!
Kind regards,
Roel
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The docs most often call this "^" a bitwise operator. It's a logical operator as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic