Write a C macro PRINT(x) which prints x

王林
Release: 2023-09-19 13:25:02
forward
1321 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  #define PRINT(x) printf(#x) int main () { PRINT(Hello); printf("

"); PRINT(26); printf("

"); PRINT(2.354721); printf("

"); }

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:
source:tutorialspoint.com
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 Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!