#include <stdio.h> #define nameof(var) #var int main() { int myVariable = 42; printf("The name of the variable is: %s\n", nameof(myVariable)); // 輸出: The name of the variable is: myVariable return 0; }
#include <stdio.h> #define typeof(var) _Generic((var), \ int: "int", \ float: "float", \ double: "double", \ char: "char", \ default: "unknown type" \ ) int main() { int myInt; float myFloat; printf("The type of myInt is: %s\n", typeof(myInt)); // 輸出: The type of myInt is: int printf("The type of myFloat is: %s\n", typeof(myFloat)); // 輸出: The type of myFloat is: float return 0; }