Home > Backend Development > C++ > Write a C macro PRINT(x) which prints x

Write a C macro PRINT(x) which prints x

王林
Release: 2023-09-19 13:25:02
forward
1489 people have browsed it

Write a C macro PRINT(x) which prints x

Here we will see how to define a macro called PRINT(x), which will print any value of x passed as argument.

To solve this problem, we will use the stringize operator. Use this operator to convert x to a string, and then by calling the printf() function internally, the value of x will be printed. Let's look at an example to get a better idea.

Example

#include <stdio.h>
#define PRINT(x) printf(#x)
int main () {
   PRINT(Hello);
   printf("</p><p>");
   PRINT(26);
   printf("</p><p>");
   PRINT(2.354721);
   printf("</p><p>");
}
Copy after login

Output

Hello
26
2.354721
Copy after login

The above is the detailed content of Write a C macro PRINT(x) which prints x. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Print sql statement
From 1970-01-01 08:00:00
0
0
0
java - Print electronic form
From 1970-01-01 08:00:00
0
0
0
How to print key value in python for in
From 1970-01-01 08:00:00
0
0
0
Unable to print data
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template