function overloading is a popular feature in languages like C++ and Java, where multiple functions can have the same name but different parameters.However, C does not support function overloading natively. But with some clever use of macros, you can simulate function overloading to a certain extent. This article will explain: Why function overloading is missing in C How macros work in C How to simulate overloading using macros Code examples Mini Project based on macro overloading 5 company-specific interview questions and answers Why C Does Not Support Function Overloading In C, function names are unique identifiers during linking.C compilers do not include type information in the function name (no "name mangling" like in C++), so having two functions with the same name would cause ambiguity at compile or link time. Introduction to Macros in C A macro is a fragment of code defined by the #define directive.Macros allow you to insert code snippets before compilation. Syntax: #define macro_name(parameters) macro_body Example: #define SQUARE(x) ((x)*(x)) Here, SQUARE(5) expands to ((5)*(5)) during preprocessing. Simulating Overloading with Macros While C macros are not true functions, you can simulate overloading behavior based on the number or types of arguments. Technique: Use macros to check the number of parameters passed and redirect to different function names. Example with a simple macro: #define add(x, y) _Generic((x), int: add_int, float: add_float)(x, y) int add_int(int a, int b) { return a + b; } float add_float(float a, float b) { return a + b; } Now: add(5, 6); // Calls add_int add(5.5f, 6.5f); // Calls add_float Understanding _Generic Keyword The _Generic keyword introduced in C11 provides a way to perform type-generic programming. Syntax: code_Generic(expression, type1: result1, type2: result2, ...) Example: code_Generic(10, int: "Integer", float: "Float") This returns "Integer" because 10 is an int. Real Example: Simulating a Print Function #include <stdio.h> #define print(x) _Generic((x), \ int: print_int, \ float: print_float, \ double: print_double, \ char*: print_string \ )(x) void print_int(int x) { printf("Integer: %d\n", x); } void print_float(float x) { printf("Float: %.2f\n", x); } void print_double(double x) { printf("Double: %.2lf\n", x); } void print_string(char* x) { printf("String: %s\n", x); } int main() { print(5); print(3.14f); print(7.89); print("Hello World"); return 0; } This prints based on the type passed. Mini Project: Type-Aware Logging System using simulating Idea Create a logging library where the log_info macro can handle different types like integers, strings, and floats by overloading behavior using _Generic. Requirements Define log_info macro Create functions to print int, float, and string logs Test with different inputs Code Skeleton (Function Overloading) #include <stdio.h> #define log_info(x) _Generic((x), \ int: log_int, \ float: log_float, \ char*: log_string \ )(x) void log_int(int val) { printf("[INFO] Integer: %d\n", val); } void log_float(float val) { printf("[INFO] Float: %.2f\n", val); } void log_string(char* val) { printf("[INFO] String: %s\n", val); } int main() { log_info(100); log_info(5.5f); log_info("Logging Started"); return 0; } This gives a clear logging mechanism for different types. Interview Questions and Answers Google Q1. Is support function overloading in C ?A1. No, function overloading in C do not support, due to lack of name mangling. However, macros and _Generic can simulate basic type-based dispatch. TCS Q2. How does the _Generic keyword help in type safety?A2. _Generic selects functions based on type at compile-time, avoiding type confusion errors and making the code type-safe. Infosys Q3. Give an example where Function Overloading via macros could be useful.A3. In libraries for math operations (e.g., overloaded add() or multiply() for int and float types). Zoho Q4. What are the risks of using macros to simulate overloading?A4. Macros do not provide type checking or debugging ease like real functions; misuse can cause hidden errors. Amazon Q5. Why is _Generic considered safer than traditional macros?A5. Unlike traditional macros, _Generic provides compile-time type selection, reducing hidden side-effects. Conclusion While C doesn't have built-in function overloading, smart usage of macros and the _Generic keyword allows developers to mimic overloading functionality in many practical scenarios.Mastering macro-based simulation techniques can make C programs more flexible, powerful, and easier to maintain.