Message from C, C++ discussions
December 2019
— As far as I understand, its not guaranteed here that a+b
or a=b
will be calculated first (at least before C++17). So this expression not guaranteed to work the same on all the compilers.
https://en.cppreference.com/w/cpp/language/eval_order
In this case we can parse the expression as a tree (picture below), it's evaluated from top to bottom. We can't evaluate minus before we evaluate both a+b
and a=b
, but as far as I know the order of these two can be any.
I can be wrong, though. But I don't see any guarantees about operators specifically.
Also check out this https://stackoverflow.com/questions/1826159/swapping-two-variable-value-without-using-third-variable
— Not in c but in c++
— 2,5
— .
— 2,5
— Oh god..
— Another one bites the dust...!
Banned Deepak.
Reason:
ad
— Btw care to explain
— User Daniyal has 1/2 warnings; be careful!
The latest warn was because:
whatsapp chat
— Void recursionBubble(int* arr, int size, int i, int j, int n){
printf("i = %d n = %d\n", i, n);
if(i >= size / sizeof(int)){
return;
}else{
if(n >= size / sizeof(int))recursionBubble(arr, size, i + 1, 0, 1);
if(arr[n] < arr[j]){
swap(&arr[n], &arr[j]);
recursionBubble(arr, size, i, j + 1, n + 1);
}else{
recursionBubble(arr, size, i, j + 1, n + 1);
}
}
}
— Why do i get seg fault