Write a C program to calculate profit or loss by using user define functions. Profit Loss Program

Explanation

  1. calculateProfitOrLossByValue Function:
    • This function takes two integers, costPrice and sellingPrice, as parameters by value.
    • It calculates the profit or loss by comparing the sellingPrice with the costPrice.
    • Since this function uses pass-by-value, any changes made to the parameters inside the function do not affect the original variables.
  2. calculateProfitOrLossByReference Function:
    • This function takes two integers (costPrice and sellingPrice) and two additional references (result and status) as parameters.
    • It calculates the profit or loss and updates the result and status variables directly.
    • Since this function uses pass-by-reference, the original variables are modified with the result of the calculation.

Output

Key Points

  • Pass-by-Value: The original costPrice and sellingPrice values remain unchanged after the function call.
  • Pass-by-Reference: The result and status variables are updated with the calculated profit or loss after the function call.