Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
23 views
8 pages
C++ Preprocessors
Uploaded by
Jaii P
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save C++_preprocessors For Later
Download
Save
Save C++_preprocessors For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
23 views
8 pages
C++ Preprocessors
Uploaded by
Jaii P
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save C++_preprocessors For Later
Carousel Previous
Carousel Next
Download
Save
Save C++_preprocessors For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 8
Search
Fullscreen
a processor Direct, tre source code, the lines thar es alt hese directives can by Greet the beginning of the on because they are not sri is discussed next ir begin with e na , wo pad anyone gt ae known Part of the le. These ins; P™Btam, but us othe hee CHE age ectveS are not te usually they are BvaKe. The lst of the pees gdefine \¢ preprocessor Finclude #if gerror zelif else Fidel line endif ifndef undef you can place only one preprocessor directive j ¢ in one line, the #define Directive the #define directive defines an identi diective is encountered in i identifier and a replacement token, Wh the subsequent occurrenc eae code, the replacement token will Spahbiiiot abseqen ces ofthe tener ge acement sok il be subsiuted foal he macro name a e. ‘ifier as the veal the proce aan some code The enter is aso known gintax is as follows: own as macro replacement. The define macro_name replacement_token For example, to use the word PI for the value 3.14159, you can write the following statement: #define PI 5 14159 Ie above example, the word PI represents the macro name and the value 3.14159 represents tereplacement token. "The #define directive directs the preprocessor to replace the word with the specified value each time it is encountered in the source code. Inthe above example, a single identifier is replaced with a specified replacement token, This Process is also known as object-like mactos- sed as function-like macros. In the function-like macros, var pave an argument ist enclosed within the is encountered, the time the identifier i passed in the program. we fieine directive can also be uses parent ine directive defines an identifier that Hl heses and the replacement token. Each aria ments within it are replaced with the actual argumentsfollows’ ayed by commas) replace ar The syntax for th oe sar ae #define macro” For example: #define SUM(a,b) (atb) ) UM(2,3)5 js encountered in the progra, ifier SUM is ae ncaa db, respectively. T ve value of (a+B). when an ident variables @ al the resultant ¥ ¢ of the #define directive. In the above example, 1 arguments (2,3) are assigned 10 ¥ the replacement token, which is The following example illustrates the us [Example 4 rogram to calculate the area of ac ‘The following program will prompt the user to enter the radius ofa circle, calculate and display the resultant value on the screen. /Mrite a program to find the area of a circle. #include
using namespace std: #define PI 3.14//Object-like macro #define AREA(t) (rr) //Function-like macro int main() double i; intj; cout<<“Enter the radius:” 7 cen lius:”<
) or in double quotes. The syntax is as follows: #include
#include “filename.h” Inthe above syntax, the .h is used as a file extension. for example: — Findude
or #include
10 read the file named t ts the compiler i fre the same. The use ive dire ( n above Inthe #include direct el «the above example, t it mple, the #inclu ve P th statements gh of, at and include it in the progran’ Bo i ; ithe lower statement is optional.612. s rective: ion pl 's source ‘= ional Compllatl tion ofthe Pragrarn’s source anna Elia eagle eet that a ee conditions. There are f aresti Conditional compilation mea in soe, #elif, Hendif, #ifdef, ang gv compiled or ignored bein ‘are #if, #else, conditional compilation. Ss The #if and #endif eee The syntax for the #if directive is a #if condition or expression statement or block of code #endif ove syntax, the statemel ck of code between the #if and nt or block of cos wee! a ¢ above syntax, em ig following the #if directive is true, ec i pression following the ee beighored Hers tie denaitabecnne refers tothe end ofthe Ht block For example: #define COUNT 10 int main( ) #if COUNT>9 . cout<<“Count is greater”; #endif } In the above example, the #define directive directs the preprocessor to substitute ay in place of COUNT. When the execution begins, the condition COUNT>9 is checked tmue. Here, the condition is true because the value 10 is greater than the value 9, So, the statement will be executed and it will display the following Statement on the screen: Count is greater The #else Directive The working of the Helse directive ig the same as the “pression specified with the #if directive is false, the directive will be compiled. The syntax is as follows: #if condition or expression Statement or block of code #else statement or block of #endif maneqomeration, and Preproce or OUNT>20 cout<<“Count is greater”; gelse . cout<<"Count is smaller’ } sample, the condition COUNT: mple i UNT >20 is false. S : vil be compiled and itil display the along statement on te sere screen theabove Or i gse dient iis smaller lif Directive ‘eis also known as the else if directive. The working of the #elif directive is ent. The syntax is as follows: e #el r spe esi rect shesame as HE elseif statem! #if condition or expression statement] #elif condition oF &XP' statement? 4elif condition or expre statement3 elif condition or exPre statement #endif ression ssion ssion if the condition or expression following the #f directive is tues he ill be compited and “iL the #elif directives will be skipped. sted. Inthe above syntax, satement associated with it Othernise, the next #elif will be te for example: #define points_scored 50 int main() #if points_scored>=90 cout< <"Grade A #elif poimts_scored>=70 cout<<"Grade BY:6-14 =50 if points_scored> =50 tee Pe < rade C i #elif points_scored> = cout<<“Fail”; #endif t ubstitutes the value 50 in the 3 . e directive substi The #if directing i hone ml ean gr ih he HE Scie identifier points_scored. Here, ht Ci ive will be checked. If it is true, it vith the next #elif direct ext #elif directive will be sete Sea ie compiled. Otherwise, the nex! tes on, jirectives i n Tne Mifdet and #ifndet Directives are also known as iCdefined and itnotg The #ifdef directis directives, respectively. The syntax of the #ifdef is as follows: #ifdef macto_name statement #endif, define statement ¢ skipped. . In the above syntax, if macro_name has already been defined in a # statement associated with #ifdef will be compiled. Otherwise, it will be For example: #ifdef JOHN cout<<"Hi, John”; #endif In this example, if the macro name JOHN h ‘ample, facto na has alteady been defined i je state the next cout statement will be compiled, : tina sein The syntax of the #ifndef is as follows: #ifndef macro_name Statement #endif In the above syntax, if the e e syntax, macro_name is i associated with #ifndet will be compiled, Other eehivernenaay . ‘ise, it will be skipped. he6-15 ple é oHN 7 oot eth John”; ‘ onl empl ifthe macro name JOHN ha poets i compe “rein yom « def pirective ut fe g directive 1s used to remove a Aone ant. The syntax is as fol & macro that has been prev it qh eso Y yntax is as follows: previously defined in a se fined in a #define statement, the onde macro_name eile fo the #define directive defines the macro COUNT. The #undef sie presions example, COUNT, which was previously defined ina #define statement. iective undefines the macro the #line Directive qfyouwant to change the contents of __LINE__and _FILE_, youcan do itwith the help of ie fline directive. The _ E__ and _FILE__ identifiers are predefined to a compiler. 1s the value, whichis the line number ofthe currently compiled identifier contan the_L Feafthe source code. The FILE i er contains a string value that specifies the sof the source file being compiled. rhe syntax ofthe #line directive is as follows: Aline value “filename” Inthe above syntax, the value spe a positive integet value, which is the new value of the -LINE_ identifier: The filename is optional. If you specify any valid filename, it becomes Denorvalue of the _ FILE_ identifier fr xample: line 10 line_directive t main() jjLine 10 Line av jjline 12 cout<<_ LID cout<<_ FILE, return 0;6-16 becomes the , unter and enti name, which becomes qh. se displays the line number, ; ‘which is Kine_directive on het sets th In this example, the value 10 reset t LINE__ identifier and line_directive © FILE _ identifier. The first Cpe other cout statement displays The #error Directive ilation of the program. The sympa, The #error directive is used to stop the compilatio i er #etror error_message Dy, vhich is displayed when the #e, 4 B cilfies the message, which ef al by the compiler, The error_message spe ee enldein " encountered along with some other infor The Operator This operator converts the argument in The # is known as the stringize operator Thi string that follows it. The syntax is as follows: # argument The stringize operator converts the value that is stored in this argument into a qu For example: #define demo(a) #a int main( ) cout<
You might also like
The Preprocessor
PDF
No ratings yet
The Preprocessor
28 pages
L9 Preprocessors in C
PDF
No ratings yet
L9 Preprocessors in C
23 pages
Week 2 Macros Continued
PDF
No ratings yet
Week 2 Macros Continued
25 pages
CTSD2 UNIT-3 Preprocessor Directives-1
PDF
No ratings yet
CTSD2 UNIT-3 Preprocessor Directives-1
55 pages
3. CTSD-2 Unit_3
PDF
No ratings yet
3. CTSD-2 Unit_3
26 pages
Pre Processor
PDF
100% (1)
Pre Processor
24 pages
Circular 3
PDF
No ratings yet
Circular 3
1 page
C Preprocessor
PDF
No ratings yet
C Preprocessor
30 pages
Scope and Preprocessor
PDF
No ratings yet
Scope and Preprocessor
34 pages
3 Preprocessing
PDF
No ratings yet
3 Preprocessing
30 pages
Preprocessor Preprocessor: List of Preprocessor Commands
PDF
No ratings yet
Preprocessor Preprocessor: List of Preprocessor Commands
8 pages
C Programming
PDF
100% (1)
C Programming
187 pages
unit 3
PDF
No ratings yet
unit 3
26 pages
Aromin - Act1 Compee
PDF
No ratings yet
Aromin - Act1 Compee
5 pages
Unit 2 Preprocessor
PDF
No ratings yet
Unit 2 Preprocessor
18 pages
PPS UNIT-III
PDF
No ratings yet
PPS UNIT-III
34 pages
Preprocessor_directives_for C_Compiler_29-May-2024_SRC.docx
PDF
No ratings yet
Preprocessor_directives_for C_Compiler_29-May-2024_SRC.docx
8 pages
PPS - UNIT-III Notes
PDF
No ratings yet
PPS - UNIT-III Notes
40 pages
7-Preprocessors-14-03-2022 (14-Mar-2022) Material - I - 14-03-2022 - Preprocessors
PDF
No ratings yet
7-Preprocessors-14-03-2022 (14-Mar-2022) Material - I - 14-03-2022 - Preprocessors
31 pages
C NOTES
PDF
No ratings yet
C NOTES
13 pages
Pre Processor Directives
PDF
No ratings yet
Pre Processor Directives
18 pages
Preprocessor directives - C++ Tutorials
PDF
No ratings yet
Preprocessor directives - C++ Tutorials
4 pages
Preprocessor Directives
PDF
100% (1)
Preprocessor Directives
7 pages
MK @MSITStore C Program Files C-Free 5 Help CLib - CHM CPP
PDF
100% (1)
MK @MSITStore C Program Files C-Free 5 Help CLib - CHM CPP
4 pages
Macro in C
PDF
No ratings yet
Macro in C
2 pages
Unit 5 PWC
PDF
No ratings yet
Unit 5 PWC
29 pages
Preprossecor Directive
PDF
No ratings yet
Preprossecor Directive
8 pages
Chapter6-Preprocessing and IO
PDF
No ratings yet
Chapter6-Preprocessing and IO
26 pages
Chapter 17 Preprocessor Directives
PDF
100% (1)
Chapter 17 Preprocessor Directives
13 pages
Lecture 2 C++ Preprocessor Directives
PDF
No ratings yet
Lecture 2 C++ Preprocessor Directives
22 pages
C lecture 7.1
PDF
No ratings yet
C lecture 7.1
11 pages
unit-5-part1-1
PDF
No ratings yet
unit-5-part1-1
5 pages
The C Preprocessor
PDF
100% (1)
The C Preprocessor
11 pages
Lesson 29
PDF
No ratings yet
Lesson 29
29 pages
C Preprocessor Directives
PDF
100% (1)
C Preprocessor Directives
8 pages
Preprocessor_in_c
PDF
No ratings yet
Preprocessor_in_c
6 pages
Unit_3
PDF
No ratings yet
Unit_3
8 pages
Chapter 13 - The Preprocessor: Outline
PDF
No ratings yet
Chapter 13 - The Preprocessor: Outline
16 pages
Pre Processor
PDF
100% (1)
Pre Processor
5 pages
rohini_89796854368
PDF
No ratings yet
rohini_89796854368
7 pages
Chapter 13 - The Preprocessor: Outline
PDF
No ratings yet
Chapter 13 - The Preprocessor: Outline
15 pages
BCA Paper-V Unit-9
PDF
No ratings yet
BCA Paper-V Unit-9
15 pages
Separate Step in The Compilation Process: Substitution Tool Pre-Processing
PDF
No ratings yet
Separate Step in The Compilation Process: Substitution Tool Pre-Processing
40 pages
Condtitional Compilation
PDF
No ratings yet
Condtitional Compilation
13 pages
Electronics Communication Engineering Tentative Syllabus.
PDF
No ratings yet
Electronics Communication Engineering Tentative Syllabus.
83 pages
Seminar 1
PDF
No ratings yet
Seminar 1
5 pages
Pre Processor Diretives
PDF
No ratings yet
Pre Processor Diretives
18 pages
Preprocessor Directives in C
PDF
0% (1)
Preprocessor Directives in C
21 pages
UNIT-5-1-Preprocessor directives
PDF
100% (1)
UNIT-5-1-Preprocessor directives
4 pages
Preprocessor in C
PDF
100% (1)
Preprocessor in C
6 pages
The C++ Preprocessor: File Inclusion
PDF
No ratings yet
The C++ Preprocessor: File Inclusion
5 pages
Preprocessors The C Preprocessor Is Not Part of TH
PDF
No ratings yet
Preprocessors The C Preprocessor Is Not Part of TH
5 pages
Preprocessor
PDF
100% (2)
Preprocessor
8 pages
C Concepts
PDF
No ratings yet
C Concepts
12 pages
Preprocessor Directives: Separate Step in The Compilation Process
PDF
No ratings yet
Preprocessor Directives: Separate Step in The Compilation Process
40 pages
Kapila Gita
PDF
No ratings yet
Kapila Gita
124 pages
Preprocessor Directives: Macro Definitions (#Define, #Undef)
PDF
No ratings yet
Preprocessor Directives: Macro Definitions (#Define, #Undef)
7 pages
C Preprocessor
PDF
No ratings yet
C Preprocessor
14 pages
Unit 4 Preprocessor Directives: 1 What Is Pre-Processor?
PDF
100% (2)
Unit 4 Preprocessor Directives: 1 What Is Pre-Processor?
6 pages
Internship Report Format & Notice
PDF
No ratings yet
Internship Report Format & Notice
3 pages
Preprocessor Derectives in C
PDF
100% (1)
Preprocessor Derectives in C
30 pages
C Preprocessor PDF
PDF
No ratings yet
C Preprocessor PDF
13 pages