Ask your own question, for FREE!
Computer Science 9 Online
OpenStudy (anonymous):

Can someone write a program using alpha=beta-- in c++? Alpha and beta being integers.

OpenStudy (anonymous):

#include <iostream> int main(int argc, char** argv) { int alpha, beta = 10; while ((alpha = beta--)) // Extra pair of parentheses suppresses warnings { std::cout << "T minus " << alpha << " and counting" << std::endl; } std::cout << "Lift-Off!" << std::endl; return 0; } Alpha isn't really needed in this case, but still.

OpenStudy (anonymous):

If you modify it a little so that you see the value of beta alongside the value of alpha, you can see that alpha is being assigned the initial values of beta that beta had before beta was decremented.

OpenStudy (anonymous):

Yes you can write a program like this in c++. I assume the question is "what happens to alpha and beta?" Answer in this case is: (1) alpha is assigned the value of beta (2) beta is decremented by one Explanation: the -- operator written behind a variable evaluates the entire expression to the current value of the variable BEFORE the decrementing operation is executed. Example: int beta, alpha; beta = 3; alpha = beta--; // now alpha is 3 and beta is 2

OpenStudy (anonymous):

Thank You!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Arriyanalol: i need help
1 day ago 7 Replies 1 Medal
Arriyanalol: CONGRATS to me
1 day ago 8 Replies 2 Medals
Legomaster346: What colleges are good that are near Arab Alabama?
1 week ago 5 Replies 0 Medals
Arriyanalol: i need help
1 week ago 6 Replies 2 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!