"C + + programs" about macros

Source: Internet
Author: User

/******************************************************//**************---about Macro----------**************// ---author:tibruce Zhao---**************//**************---date:2015/7/31------**************//*** /#include <iostream> #include <stdio.h>//this is Macro. #define PI 3.1415926//#define H printf ("Hello,the world!\n");//sign "\" for continuation character # define I int n;printf ("Please enter an integer:"); scanf ("%d", &n);p rintf ("you entered half of%d \ n", n+n), using namespace std; #ifndef h//if not defined h#define H cout<< "Hello,the Chain !!" <<endl; #else # define __h H #undef H//Cancel the definition of H. #-H "* * *" #endif//Standard Model #ifndef vx#define VX 1int x=3; #endif//Definition functions, macro functions. #define SWAP (t,x,y) {T t=x;x=y;y=t;} #define MAX (x, y) x<y?y:x#define STR (x) puts (#x)//"#" changes the argument to the corresponding string void Welcomestudent () {printf ("Welcome fellow students \ \");} void Welcomestudent () {STR (welcome fellow students);} void Welcometeacher () {printf ("Welcome to teachers \ \");} #define Welcome (WHO) welcome# #who ()//# #用于拼接int main () {HiintA=10,b=20;double c=12.3,d=45.6; SWAP (int,a,b);//{t t=x;x=y;y=t;} SWAP (double,c,d);p rintf ("a=%d,b=%d\n", A, b);p rintf ("c=%g,d=%g\n", C,d);p rintf ("%d\n", MAX (b)),//printf ("%d\n", MAX (++a,++b));//macro function preferably without such operator (+ +) cout<< "*******************************************" <<endl; STR ("Hello,the world!"); Welcome (student); welcome (teacher); return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"C + + programs" about macros

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.