Program to update even number into its upper nearest odd number. C++ Program to update even to odd

Explanation

  1. updateToUpperOddByValue Function:
    • This function takes an integer as a parameter by value.
    • It checks if the number is even (i.e., divisible by 2), and if so, it increments the number by 1 to make it odd.
    • Since the function uses pass-by-value, changes made inside the function do not affect the original variable.
  2. updateToUpperOddByReference Function:
    • This function takes an integer as a parameter by reference.
    • It checks if the number is even, and if so, it increments the number by 1 to make it odd.
    • Since the function uses pass-by-reference, changes made inside the function directly affect the original variable.

Output

Key Points

  • Pass-by-Value: The original value of x remains unchanged after the function call.
  • Pass-by-Reference: The original value of x is updated to the nearest upper odd number after the function call.