- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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));
Advertisements