51. void pointer and Casting

You are writing a utility function that adds two values — but the values can be either:

  • int, or
  • float

You will be given void* pointing to the first and second value and a char type specifier: 'i' for int, 'f' for float.

Your task is to:

  • Cast the void* to appropriate type based on the specifier
  • Perform the addition
  • Print the result (as integer or float)

Use proper void* casting and dereferencing logic


Example-1

Input: type = i, a = 10, b = 20
Output: 30


Example-2

Input: type = f, a = 3.5, b = 2.5
Output: 6.0


Example-3

Input: type = i, a = -5, b = 7
Output: 2


 

Loading...

Input

i 10 20

Expected Output

30