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

Code for Small C++ Class to Transform Any Static Control into a Hyperlink Control?

0 Answers   Wipro,


PROBLEM #8 The cashier at the counter of a Super Store, Mr. Khazaanchi has the following bundles of rupee cash notes with him: Rs. 1, 2, 5, 10, 50, 100, 500, 1000 A customer comes at his counter with various items that he has shopped. Mr. Khazaanchi totals the item prices and tells the customer his total amount payable. The customer gives Mr. Khazanchi some amount of cash. Find the total number of rupee notes of each denomination (i.e. 1, 2, 5, 10, 50, 100, 500, 1000) Mr. Khazaanchi will have to give to the withdrawer ensuring that the total number of rupee notes are minimum.

1 Answers   AR, ARJ,


write a program that accepts a number and outputs its equivalent in words. take note that the maximum input is 3000

1 Answers   Alvin,


Min-Max Write an algorithm that finds both the smallest and largest numbers in a list of n numbers and with complexity T(n) is at most about (1.5)n comparisons.

10 Answers   ABC, College School Exams Tests, ITC Infotech, Kyambogo University, Qatar University,


write a program to calculate the radius for a quadratic equation use modular programming(function abitraction)hint use quadratic function

1 Answers   ICAN, Jomo Kenyatta University,






Here's the programm code: int magic(int a, int b) { return b == 0 ? a : magic(b, a % b); } int main() { int a, b; scanf("%d%d", &a, &b); printf("%d\n", magic(a, b)); return 0; } on input stream we have integers 4, 45 What's the output integer? How many times will be initiated "magic" function?

1 Answers  


Implement a command console for changing settings on a particular object. The command console should allow you to enter a string and will return the response (very similar to a terminal session). The commands are as follows: SET propertyname=newvalue will change the target object’s member named “propertyname” to have a value equal to “newvalue”. If the input value is incompatible (i.e. an int being set to a string), print out an appropriate error message. GET propertyname will print out the current value of the target object’s member named “propertyname”. GET * will print out a list of all target object members and their current values. The system should be extensible for future commands and should accept an arbitrary object, such that another developer could insert another object into the system and rely on the command console to get and set the properties correctly.

0 Answers   ABC, Guidance Software,


Show by induction that 2n > n2, for all n > 4.

2 Answers   Karvy, Qatar University,


program to find the magic square using array

1 Answers  


Definition of priority queue was given. We have to implement the priority queue using array of pointers with the priorities given in the range 1..n. The array could be accessed using the variable top. The list corresponding to the array elements contains the items having the priority as the array index. Adding an item would require changing the value of top if it has higher priority than top. Extracting an item would require deleting the first element from the corresponding queue. The following class was given: class PriorityQueue { int *Data[100]; int top; public: void put(int item, int priority); // inserts the item with the given priority. int get(int priority); // extract the element with the given priority. int count(); // returns the total elements in the priority queue. int isEmpty(); // check whether the priority queue is empty or not. }; We had to implement all these class functions.

0 Answers   Nagarro, Wollega 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  


Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)

0 Answers   iGate,


Categories