what is the diffrence between ++x , x++ pleaaaaase ???

Answers were Sorted based on User's Feedback



what is the diffrence between ++x , x++ pleaaaaase ???..

Answer / dallasnorth40

++ before the variable increments the variable before the
value is taken/used.
++ after the variable takes/uses the value, then increments.

Given:
int x = 5;
int y = 0;

y = x++;
This will leave y = 5 and x = 6.


y = ++x;
This will leave y = 6 and x = 6.

Is This Answer Correct ?    27 Yes 3 No

what is the diffrence between ++x , x++ pleaaaaase ???..

Answer / abhishek

This means if you declare the value for x=2 and used in
loop, while printing the value of ++x it will print 3 and if
used x++ then it will print 2 and then increment the value
for x and then next rotation it will print 3.
eg.1)
.....
..
..
++x OR x++;
printf("value of " ++x OR x++);
...
..
..

Is This Answer Correct ?    23 Yes 3 No

what is the diffrence between ++x , x++ pleaaaaase ???..

Answer / sailaxmi

++x is pre-increment

say for example
the value of a=1
int a,r;
r= ++a;

now the value of "a" is incremented to 2 n then assigned to r...


x++ is post increment
say for exmaple

the value of a is 3

int a,r;
r=a++;

the value of a(initially 3) will be assigned to r..... n
then the value of "a" gets incremented to 4.

Is This Answer Correct ?    6 Yes 1 No

what is the diffrence between ++x , x++ pleaaaaase ???..

Answer / divya prabhu

++x means preincrement x, and then assign .
i.e
first increment x ==> x+1 and then assign the incremented
value back to x ==> x=x+1


x++ means postincrement x, and then assign .
i.e
first assign value of x to x==> x and then increment value of
x, x ==> x+1

Is This Answer Correct ?    4 Yes 1 No

what is the diffrence between ++x , x++ pleaaaaase ???..

Answer / chandrakant rohi

++x
it means pre-increament ,before execute the x first it increment
Ex int x=10;
printf("%d",++x);

ans=11
and
x++ means post_increament,first excute the statment and then increment ;
Ex
int x=10;
printf("%d",x++);
ans =10;

Is This Answer Correct ?    5 Yes 2 No

what is the diffrence between ++x , x++ pleaaaaase ???..

Answer / prabu

++x mean pre increament
eample:

for(i=1;i<=1;i++)
{
printf("i value is=",i);
}
the output: i=1
x++ mean post increament
example:
for(i=1;i<=1;++1)
{
printf("i value is =",i);
}

the output: i=2

Is This Answer Correct ?    2 Yes 2 No

what is the diffrence between ++x , x++ pleaaaaase ???..

Answer / shaleen

their is not any difference betweem any two.

Is This Answer Correct ?    1 Yes 29 No

Post New Answer

More C++ Code Interview Questions

Write a program using two-dimensional arrays that determines the highest and lowest of the 12 input values. Example: Enter 12 numbers: 13 15 20 13 35 40 16 18 20 18 20 14 highest: 40 lowest: 13

1 Answers  


1. Write a program that performs the following. The user inputs a number and then enters a series of numbers from 1 to that number. Your program should determine which number (or numbers) is missing or duplicated in the series, if any. For example, if the user entered 5 as the initial number and then entered the following sequences, the results should be as shown. Input Sequence Output ---------------------- --------------- 1 2 3 4 5 Nothing bad However, if 7 were the high number, the user would see the results on the right for the following number entries: Input Sequence Output ---------------------- --------------- 1 3 2 4 5 Missing 6 Missing 7 And if 10 were the high number and the user entered the numbers shown on the left, note the list of missing and duplicate numbers: Input Sequence Output ---------------------- --------------- 1 2 4 7 4 4 5 10 8 2 6 Duplicate 2 ( 2 times) Missing 3 Duplicate 4 ( 3 times ) Missing 9

1 Answers  


write a program using virtual function to find the transposing of a square matrix?

0 Answers  


void main() { int i,j=2; for(i=0;i<3;i++) if(j=i) cout<<"Lotus "; else cout<<"Rose "; } Its result is Rose Lotus Lotus.. How? Explain it?

2 Answers  


Write a program that print in screen a tree with its height taken from user by entering number of 4 digits and find the odd numbers then calculate the sum of odd numbers so he get the height of tree?

0 Answers  






Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.

2 Answers   TCS,


Display Pattern: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 &#8230;

2 Answers   Mind Tree,


what is the difference between int &r and int& r

3 Answers  


Algorithm in O(2n) Presently we can solve in our hypothetical machine problem instances of size 100 in 1 minute using algorithm A, which is a O(2n). We would like to solve instances of size 200 in 1 minute using algorithm A on a new machine. What is the speed of the new machine should be?

2 Answers   ABC, Qatar University,


Given a table of the form: Product Sold on A 1/1/1980 B 1/1/1980 C 1/1/1980 A 1/1/1980 B 1/1/1980 C 2/1/1980 A 2/1/1980 There are 30 products and 10,000 records of such type. Also the month period during which sales happened is given to u. Write the program to display the result as: Product Month No. of copies A January 12 A February 15 A March 27 B January 54 B February 15 B March 10 C January 37

0 Answers  


Find the maximum product of three numbers in an array? Eg. 9,5,1,2,3 Max product= 9*5*3= 135 The array can hav negative numbers also..

7 Answers   CTS,


Complexity T(n) What is the time complexity T(n) of the following portions of code? For simplicity, you may assume that n is a power of 2. That is, n = 2k for some positive integer k. a) ? for (i = 1; i <= n; i++) { j = n; cout << i << ? ? j << ? ? << endl; } b) ? for (i = 0; i <= n; i += 2) { j = n; cout << i << ? ? j << ? ? << endl; } c) ? for (i = n; i >= 1; i = i/2) { j = n; cout << i << ? ? j << ? ? << endl; } d) for (i = 1; i <= n; i++) { j = n; while (j >= 0) { cout << i << ? ? j << ? ? << endl; j = j - 2; } }

0 Answers   Qatar University,


Categories