C C++. (preprocessor directives), C C++ C/C++... C++, C. C++ C. C C++. C,, C++, C++., C++.,..
#define #elif #else #error #if #itdef #ifndef #include #line #pragma #undef #.,.,. #include <stdio.h> #include <stdlib.h> #define (, ). (macro name).. #define macro-name char-sequence.., 1 LEFT, 0 RIGHT #define. #define LEFT 1 #define RIGHT 0 LEFT RIGHT, 1 0., 0 1 2.
printf( %d %d %d, RIGHT, LEFT, LEFT+1);., ONE, TWO, THREE. #define ONE 1 #define TWO ONE+ONE #define THREE ONE+TWO.. #define E_MS standard error on input\n /*... */ printf(e_ms); E_MS standard error on input\n. printf( ). printf( standard error on input\n );., this is a test XYZ. #define XYZ this is a test printf( XYZ ); (\). #define LONG_STRING this is a very long \ string that is used as an example
C/C++.., #define..,., #define.. #define MAX_SIZE 100 /*... */ float balance[max_size]; /*... */ for(i=0;i<max_size;i++) printf( %f, balance[i]); /*... */ for(i=0;i<max_size;i++) x =+ balance[i]; MAX_SIZE balance balance, MAX_SIZE.. #define.,., (function like macro). (function like macro)..
#include <stdio.h> #define ABS(a) (a)<0? -(a) : (a) int main(void) { printf( abs of -1 and 1: %d %d, ABS(-1), ABS(1)); } return 0; a 1 1. a., ABS(10 20). 10-20<0? -10-20 : 10-20.,.,.
#error. (debugging). #error. #error error-message error message. #error. #include. (angle bracket). C/C++. #include stdio.h #include <stdio.h> #include. include.. C 8 include. C++ 256 include....
....,. files, C++ C++ #include. C++, C++... 2.. (conditional compilation). #if, #else, #elif.. #if.
#if constant-expression statement sequence #if #ednif. #if.. /* #if */ #include <stdio.h> #define MAX 10 int main(void) { #if MAX>99 printf( Compiled for array greater than 99.\n ); } return 0; MAX 99. #if., ( ). #else C++ else, #if,.. /* #if/else */ #include <stdio.h> #define MAX 10 int main(void)
{ #if MAX>99 printf( Compiled for array greater than 99.\n ); #else printf( Compiled for small array.\n ); } return 0;, MAX 99 #if., #else complied for small array. #else #if #else. #if. #elif else if if else if. #elif. #elif.. #elif. #if expression statement sequence #elif expression 1 statement sequence #elif expression 2 statement sequence #elif expression 3 statement sequence #elif expression 4... #elif expression N
statement sequence, ACTIVE_COUNTRY. #define US 0 #define ENGLAND 1 #define JAPAN 2 #define ACTIVE_COUNTRY US #if ACTIVE_COUNTRY == US char currency[] = dollar ; #elif ACTIVE_COUNTRY == ENGLAND char currency[] = pound ; #else char currency[] = yen ; C #if #elif 8. C++ 256., #else, #elif #if #elif.,. #if MAX>100 #if SERIAL_VERSION int port=198; #elif int port=200; #else char out_buffer[100];
if definedif not defined #ifdef #ifndef. #ifdef. #ifdef macro-name statement sequence macro_name #define. #ifdef #ifndef #else #elif. #include <stdio.h> #define TED 10 int main(void) { #ifdef TED printf( Hi Ted\n ); #else printf( Hi anyone\n ); #ifndef RALPH printf( RALPH not defined\n ); } return 0; Hi Ted RALPH not defined., TED Hi anyone RALPH not defined. #ifdef #ifndef 8. ANSI C++ 256.
#undef.,. #undef. #undef macro-name, LEN WIDTH #undef. #define LEN 100 #define WIDTH 100 char array[len][width]; #undef LEN #undef WIDTH /* LEN WIDTH */ #undef. #ifdef., defined #ifdef. defined. defined macro-name
macro name.., MYFILE. #if defined MYFILE #ifdef MYFILE defined!., DEBUG. #if!defined DEBUG printf( Final version!\n ); defined #elif. #line _LINE_ _FILE_. _LINE_. _FILE_. #line. #line number filename number _LINE_. filename _FILE_. #line
., 100 printf( ) #line 100 102. #include <stdio.h> #line 100 /* */ void main(void) /* 100 */ { /* 101 */ printf( %d\n, LINE ); /* 102 */ return 0; } #pragma.,. #pragma..,., # ##. #define. # (stringize)
.. #include <stdio.h> #define mkstr(s) # s int main(void) { printf(mkstr(i like C++)); } return 0;. printf(mkstr(i like C++)); printf( I like C++ ); ## (pasting operator).. #include <stdio.h> #define concat(a, b) a ## b int main(void) { int xy = 10; printf( %d, concat(x, y)); } return 0;.
printf( %d, concat(x, y)); printf( %d, xy); C/C++.. C 5.. _LINE FILE DATE TIME STDC cplusplus _LINE_ _FILE_ #line. _DATE_ / /.. _TIME_. : :. _STDC_ C/C++. ( ) C++. C++ 6 _cplusplus. C++ 5 5
. C89 /* */. (*) (/).., hello. #include <stdio.h> int main(void) { printf( hello ); /* printf( there ); */ return 0; } (multilane comment).. /* */.. x = 10+ /* */5;.
swi/* */tch(c) {...,..,.,. /* x = y/a /* */ */ C++.,., (Single Line Comments). //.. //. C89 C C C99...,,.,,.