OA. free
Free
IBM Core Computer Science Core Computer Science Medium

How to call a function with arguments without using the function name?

IBM technical mcq question, verified with a worked answer. Free to practise - no sign-up.

How to call a function with arguments without using the function name?

Pick ONE option

Choose one option.
Show answer & explanation
Answer: B. Function pointer

A function pointer stores the address of a function and allows calling that function indirectly through the pointer without using its original name. Typedefs are used only to create type aliases and do not enable function invocation. Therefore, only function pointers provide the mechanism to call a function with arguments while bypassing its original name.

Step-by-step Derivation:
To call a function without using its name, you need an indirect reference to it. Function pointers provide exactly this capability:

// Original function
int add(int a, int b) {
    return a + b;
}

// Create a function pointer and assign the function address
int (*ptr)(int, int) = &add;  // or simply = add (decay to pointer)

// Call function via pointer WITHOUT using the name 'add'
int result = ptr(5, 3);  // Calls add(5, 3) indirectly

Typedefs alone cannot invoke functions—they only create type aliases for convenience. While you could use typedef to create a function pointer type, the typedef itself doesn't enable calling a function; only the function pointer does. Therefore, the answer is B.