
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
How to print a variable name in C?
The following is an example to print variable name.
Example
#include <stdio.h> #define VariableName(name) #name int main() { int name; char ch; printf("The variable name : %s", VariableName(name)); printf("
The variable name : %s", VariableName(ch)); return 0; }
Output
The variable name : name The variable name : ch
In the above program, the variable names are printed by defining the method before main()
#define VariableName(name) #name
Two variables of different datatypes are declared. By using the defined function, variable names are printed.
int name; char ch; printf("The variable name : %s", VariableName(name)); printf("
The variable name : %s", VariableName(ch));
- Related Articles
- Bash Printf - How to Print a Variable in Bash
- Print Single and Multiple variable in C#
- How to get a variable name as a string in Python?
- How to get a variable name as a string in PHP?
- How to declare a variable in C++?
- How to define a variable in C++?
- How to execute a JavaScript function using its name in a variable?
- How to print a name multiple times without loop statement using C language?
- How to print double quotes with the string variable in Python?
- How to print current activity name in android?
- How to print current package name in android?
- How to load a JavaScript function using the variable name?
- How to declare a global variable in C++
- How to modify a const variable in C?
- How to assign a reference to a variable in C#

Advertisements