Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the following code invoke UB?

Tags:

People also ask

What is UB in coding?

In computer programming, undefined behavior (UB) is the result of executing a program whose behavior is prescribed to be unpredictable, in the language specification to which the computer code adheres.

What type of behavior C is undefined?

According to the C standards, signed integer overflow is undefined behaviour too. A few compilers may trap the overflow condition when compiled with some trap handling options, while a few compilers simply ignore the overflow conditions (assuming that the overflow will never happen) and generate the code accordingly.

Why does C have undefined behavior?

When we run a code, sometimes we see absurd results instead of expected output. So, in C/C++ programming, undefined behavior means when the program fails to compile, or it may execute incorrectly, either crashes or generates incorrect results, or when it may fortuitously do exactly what the programmer intended.


Does the following code invoke UB ?

int main(){
  volatile int i = 0;
  volatile int* p = &i;
  int j = ++i * *p;
}