The Unpredictablilty of the Order of Evaluation of Subexpressions [duplicate] - c++

This question already has answers here:
Undefined behavior and sequence points
(5 answers)
Multiple increment operators in single statement [duplicate]
(5 answers)
Closed 9 years ago.
Please tell me what this line will print in c++
int a = 5;
cout<<++a <<" " <<++a <<" " <<++a <<endl;
in the book "Schaum's programming with c++" it is given that it will proceed from right to left and output will be
8 7 6
but I am getting output as
8 8 8
Please explain, is there any modification in the C++ language after the book was written?

It's undefined behavior; you could get any results, your program could
crash, or send an insulting letter to your boss. Any book which has this as an example, and specifies some specific output for it, should be thrown in the trash; the author doesn't know C++;

Related

C2041 Illegal Digit for base 8 error preventing program from compiling [duplicate]

This question already has answers here:
C++ illegal digit, simple issue
(4 answers)
How does C Handle Integer Literals with Leading Zeros, and What About atoi?
(8 answers)
Closed last year.
Hello I'm a college student and I'm using Visual Studios 2022 for my C++ class,
I was doing a project and I couldn't debug it. This is what it shows when I press f5:
Remove zero from the beginning of const int STUDENT_ID = 0488319

A strange output in C++ [duplicate]

This question already has answers here:
Strange numbers when array is not initialized in C++ [duplicate]
(3 answers)
What happens to a declared, uninitialized variable in C? Does it have a value?
(9 answers)
Closed 1 year ago.
I have tried a simple code and found a strange error(wrt me)
it is something like s[10]
now i have put some number of values into this array.t
like s[0]=0;s[1]=1.s[2]=2 and all others are empty.
now i put a for loop to see how it goes and to my surprise after index 2, some random numbers popping up in output and idk why. It should be null and the loop should have exited but here, it gives me some output like 01248766575...
why is it happening? pls do help me if u know

How to use strings with switch [duplicate]

This question already has answers here:
Why can't the switch statement be applied to strings?
(22 answers)
Evaluate a string with a switch in C++ [duplicate]
(7 answers)
C/C++ switch case with string [duplicate]
(10 answers)
C/C++: switch for non-integers
(17 answers)
Closed 2 years ago.
I am brand new to programming. I have only learned up to functions in c++ so far, so please answer with in the scope of my knowledge.
I am working of a bank account program and I want to use a switch to get the user to input whether they want to deposit or withdraw.
I know I can use an int or even a char and do some like “D” for deposit but that’s not what I want to do.
I want to able to use the whole string “deposit” with the switch statement.
Thank you!
The switch statement in c++ only supports integer types or values that can be evaluated to an integer. At best you could write a function to evaluate your strings to an integer as mentioned here
ref: Evaluate a string with a switch in C++

Confusion with operators [duplicate]

This question already has answers here:
Undefined behavior and sequence points
(5 answers)
Closed 9 years ago.
int i=c++ + c++;
Where c is also a integer and has a value of 5.
I thought the answer for this one is 12 or 11! But as it turns out it is 10.
Can anyone explain?
Thanks in advance..
It seems to be undefined behavior. See this post for further information:
Undefined behavior and sequence points

How does C++ understand two letter characters [duplicate]

This question already has answers here:
Multicharacter literal in C and C++
(6 answers)
What do single quotes do in C++ when used on multiple characters?
(5 answers)
Closed 9 years ago.
C++ seems to allow up to four characters to be held in single quotes, such as:
char c = 'abcd';
but at runtime, only the last value ('d') seems to be actually stored away. This behavior seems to happen for pairs of two, three, or four (at five the compiler finally calls uncle). But what's the deal with this design? I don't really see the logic in it.