VOOZH about

URL: https://www.geeksforgeeks.org/c/how-to-print-a-variable-name-in-c/

⇱ How to print a variable name in C? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to print a variable name in C?

Last Updated : 2 Jan, 2025

Printing a variable name means printing the identifier that is assigned to the variable. To print it, it should be in the form of string. This can be done by using stringification.

Stringification in C is the method to convert the argument of a function like macro to a string. This can be done with the help of stringize operator # and define preprocessor. Let's take a look at an example:


Output
name_of_var

Explanation: The name of the variable is passed to the function like macro STRINGIZE_THIS() and it converts it to string by inclosing it in double quotes. Basically it converts the statement STRINGIZE_THIS(name_of_var) to "name_of_var". Then this string is easily printed by the printf() function.

Comment