Question about auto increment auto decrement unary operator syntax

• 06-13-2013, 01:35 PM
maxwell55
Question about auto increment auto decrement unary operator syntax
If I run the following code in firebug the output equals 0
Code:

```y = 5; x = 0; z = 1; newnum = y++ + ++x + x++ + z++ - z++ - y--;```
If I test x, y and z on their own in firebug the output is -

Code:

```y++;  //  5 ++x;  // 1 x++;  // 0 z++;  // 1 y--;  // 5```
this makes newnum look like

newnum2 = 5 + 1 + 0 + 1 - 1 - 5; // which outputs 1 in firebug

Is there a particular reason the output of newnum is 0 rather than 1?

Best regards Maxwell
• 06-13-2013, 03:40 PM
y = 5;
x = 0;
z = 1;

newnum = y++ + ++x + x++ + z++ - z++ - y--;

in human language this means:
(return y which is 5, then do y+1) ---------> 5
+
(do x+1, then return x) ---------> 1
+
(return x, then do x + 1) ---------> 1
+
(return z, then do z+1) ---------> 1
-
(return z, then do z+1) ---------> 2
-
(return y, then do y-1) ---------> 6

so we have 5+1+1+1-2-6=0
• 06-14-2013, 02:31 AM
maxwell55
I still don't understand how y-- can equal 6 when it originally contained 5
• 06-14-2013, 03:50 PM
007Julien
Y was originally 5, but it has been modified to 6 !
• 06-15-2013, 12:41 AM
again. we have

y = 5;
x = 0;
z = 1;

newnum = y++ + ++x + x++ + z++ - z++ - y--;

y++ means: take var y (which is 5 now) for the newnum math adding operation, then increase it by 1
the same with all var++
but
++x means: increase x by 1, then take it (being 1 now, not 0) for the newnum math adding operation

X vBulletin 4.2.2 Debug Information

• Page Generation 0.08055 seconds
• Memory Usage 2,348KB
• Queries Executed 11 (?)
Template Usage (20):
• (2)bbcode_code_printable
• (1)footer
• (1)gobutton
• (1)navbar_moderation
• (1)navbar_noticebit
• (2)option
• (1)spacer_close
• (1)spacer_open

Phrase Groups Available (3):
• global
• postbit
Included Files (19):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/class_bbcode_alt.php
• ./includes/class_bbcode.php
• ./includes/functions_bigthree.php
• ./includes/functions_notice.php

Hooks Called (41):
• init_startup
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• bbcode_fetch_tags
• bbcode_create
• bbcode_parse_start
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates