Calling function with variable that is being initialized [duplicate]

I want to know that are the above two highlighted statements UB because x and y are not initialized and the user is passing those to the function by value?

Yes, your understanding is correct. The variable x and y are uninitialized local variables and they’re being used/passed by value when calling the functions. Thus, the program has undefined behavior as x and y have indeterminate values and you’re using/copying those values to the parameter of the function.

Leave a Comment