Boiz's C ++ memo (1)

xiaoxiao2021-03-06  62

This article is mainly to record some primary, but sometimes I have been easily ignored or forgotten, and only make a memorandum.

1), engagement /

/ In C , it can be used as a symbol (forgot the specification, is it called, sweating one ~), for example:

// this is Memo /

this is memo too

The above two lines are in C , the compiler will think it is a line.

However / usually only in the macro definition, because if it is a string, don't write the semicolil, such as: char * s = "how" "are" "" You? "; If it is a general statement, then directly change , Such as int sum = i j;

2)##

## is called an instruction paste, its English terminology called token-Pasting Operator, mainly in the macro definition. Use examples as follows:

#define paster (n) printf ("token" #n "=% d", token ## n)

INT token9 = 9;

Use the way as follows,

Paster (9); // Out: taken9 = 9

The above macro is equivalent to

Printf ("token" "9" "=% D", token9);

The result is:

Printf ("token9 =% D", token9);

3), division operator

/: Singhing, pay attention to the difference between the integer to remove the floating point number. If 3/2, the result = 1.3.0 / 2 is equal to 1.5.

%: Damo operator, 5% 3 = = 2

The first part is written first, and it will be sorted out in the future.

转载请注明原文地址:https://www.9cbs.com/read-86369.html

New Post(0)