Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between x++ and ++x [duplicate]

Tags:

c++

javascript

Possible Duplicate:
Incrementing in C++ - When to use x++ or ++x?

What is the difference between x++ and ++x ?

like image 832
steve Avatar asked Nov 15 '10 15:11

steve


People also ask

What is difference between X and X?

'x' indicates that this value is a single character and can be stored by a variable having the data type as char. Whereas “x” indicates that even though it's a single character but it is going to be stored in the variable having data type as String.

What is the difference between x and x in C ++?

In C and C++, "x" is of type const char[] which is an array and it is null-terminated (0x00). Whilst 'x' is of type char . The datatype std::string . C++ has support in the standard library for the String datatype, which can be assigned a const char[] .

Can a function repeat X?

A function is a special kind of relation. In a function, there can only be one x-value for each y-value. There can be duplicate y-values but not duplicate x-values in a function.

What is the x value of a function?

x is the value of the x-coordinate. This form is called the slope-intercept form. If m, the slope, is negative the functions value decreases with an increasing x and the opposite if we have a positive slope.


2 Answers

x++ executes the statement and then increments the value.

++x increments the value and then executes the statement.

var x = 1;
var y = x++; // y = 1, x = 2
var z = ++x; // z = 3, x = 3
like image 157
Justin Niessner Avatar answered Oct 04 '22 14:10

Justin Niessner


x++ returns x, then increments it.

++x increments x, then returns it.

like image 28
Rocket Hazmat Avatar answered Oct 04 '22 13:10

Rocket Hazmat