SlideShare a Scribd company logo
1 of 9
# and ## Operators in C
Stringizing operator (#)
• This operator causes the corresponding actual argument to be enclosed in double
quotation marks. The # operator, which is generally called the stringize operator,
turns the argument it precedes into a quoted string. For more on pre-processor
directives – refer this
Examples :
• The following preprocessor turns the line printf(mkstr(geeksforgeeks));into
printf(“geeksforgeeks”);
• // CPP program to illustrate (#) operator
• #include <stdio.h>
• #define mkstr(s) #s
• int main(void)
• {
• printf(mkstr(geeksforgeeks));
• return 0;
• }
• Output:
• geeksforgeeks
In this program, value of a is replaced
by macro.
• // CPP program to illustrate (#) operator
• #include <iostream>
• using namespace std;
• #define a 8.3297
• int main()
• {
• cout << "Value of a is " << a << endl;
• return 0;
• }
• Output:
• Value of a is 8.3297
This program finds out maximum out of two numbers
using macro
• // CPP program to illustrate (#) operator
• #include <iostream>
• using namespace std;
• #define MAX(i, j) (((i) > (j)) ? i : j)
• int main()
• {
• int a, b;
• a = 250;
• b = 25;
• cout << "The maximum is " << MAX(a, b) << endl;
• return 0;
• }
• Output:
•
The maximum is 250
Token-pasting operator (##)
• Allows tokens used as actual arguments to be
concatenated to form other tokens. It is often useful to
merge two tokens into one while expanding macros.
This is called token pasting or token concatenation. The
‘##’ pre-processing operator performs token pasting.
When a macro is expanded, the two tokens on either
side of each ‘##’ operator are combined into a single
token, which then replaces the ‘##’ and the two
original tokens in the macro expansion.
Examples :
• The preprocessor transforms printf(“%d”, concat(x, y));
into printf(“%d”, xy);
The preprocessor transforms printf(“%d”, concat(x, y));
into printf(“%d”, xy);
• // CPP program to illustrate (##) operator
• #include <stdio.h>
• #define concat(a, b) a##b
• int main(void)
• {
• int xy = 30;
• printf("%d", concat(x, y));
• return 0;
• }
• Output:
• 30
• Application: The ## provides a way to
concatenate actual arguments during macro
expansion.
• If a parameter in the replacement text is
adjacent to a ##, the parameter is replaced by
the actual argument, the ## and surrounding
white space are removed, and the result is re-
scanned.
# and ## Operators in C ?
• In this section we will see what are the Stringize operator(#) and
Token Pasting operator(##) in C. The Stringize operator is a
preprocessor operator. It sends commands to compiler to convert a
token into string. We use this operator at the macro definition.
• Using stringize operator we can convert some text into string
without using any quotes.
• Example
• #include<stdio.h>
• #define STR_PRINT(x) #x
• main()
• {
• printf(STR_PRINT(This is a string without double quotes));
• }
• Output
• This is a string without double quotes
• The Token Pasting operator is a preprocessor operator.
It sends commands to compiler to add or concatenate
two tokens into one string. We use this operator at the
macro definition.
• Example
• Live Demo
• #include<stdio.h>
• #define STR_CONCAT(x, y) x##y
• main()
• {
• printf("%d", STR_CONCAT(20, 50));
• }
• Output
• 2050

More Related Content

What's hot

RichControl in Asp.net
RichControl in Asp.netRichControl in Asp.net
RichControl in Asp.net
Bhumivaghasiya
 
Relational Algebra-Database Systems
Relational Algebra-Database SystemsRelational Algebra-Database Systems
Relational Algebra-Database Systems
jakodongo
 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewing
Mohd Arif
 

What's hot (20)

android menus
android menusandroid menus
android menus
 
RichControl in Asp.net
RichControl in Asp.netRichControl in Asp.net
RichControl in Asp.net
 
Software Process Improvement
Software Process ImprovementSoftware Process Improvement
Software Process Improvement
 
1. digital image processing
1. digital image processing1. digital image processing
1. digital image processing
 
Analysis modeling
Analysis modelingAnalysis modeling
Analysis modeling
 
File Pointers
File PointersFile Pointers
File Pointers
 
Introduction to 2D/3D Graphics
Introduction to 2D/3D GraphicsIntroduction to 2D/3D Graphics
Introduction to 2D/3D Graphics
 
Model1 Active and Passive Graphics.pptx
Model1 Active and Passive Graphics.pptxModel1 Active and Passive Graphics.pptx
Model1 Active and Passive Graphics.pptx
 
Analysis modelling
Analysis modellingAnalysis modelling
Analysis modelling
 
Computer Aided Software Engineering Nayab Awan
Computer Aided Software Engineering Nayab AwanComputer Aided Software Engineering Nayab Awan
Computer Aided Software Engineering Nayab Awan
 
11 deployment diagrams
11 deployment diagrams11 deployment diagrams
11 deployment diagrams
 
State Diagrams
State DiagramsState Diagrams
State Diagrams
 
Computer Graphics - clipping
Computer Graphics - clippingComputer Graphics - clipping
Computer Graphics - clipping
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
 
Relational Algebra-Database Systems
Relational Algebra-Database SystemsRelational Algebra-Database Systems
Relational Algebra-Database Systems
 
Software Metrics
Software MetricsSoftware Metrics
Software Metrics
 
Computer graphics notes
Computer graphics notesComputer graphics notes
Computer graphics notes
 
Chapter 1 2 - some size factors
Chapter 1   2 - some size factorsChapter 1   2 - some size factors
Chapter 1 2 - some size factors
 
Compiler Design Unit 4
Compiler Design Unit 4Compiler Design Unit 4
Compiler Design Unit 4
 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewing
 

Similar to # And ## operators in c

05 -working_with_the_preproce
05  -working_with_the_preproce05  -working_with_the_preproce
05 -working_with_the_preproce
Hector Garzo
 

Similar to # And ## operators in c (20)

05 -working_with_the_preproce
05  -working_with_the_preproce05  -working_with_the_preproce
05 -working_with_the_preproce
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
Preprocessors
PreprocessorsPreprocessors
Preprocessors
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
 
Python_Functions_Unit1.pptx
Python_Functions_Unit1.pptxPython_Functions_Unit1.pptx
Python_Functions_Unit1.pptx
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
cp Module4(1)
cp Module4(1)cp Module4(1)
cp Module4(1)
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
Unit 5 Part 1 Macros
Unit 5 Part 1 MacrosUnit 5 Part 1 Macros
Unit 5 Part 1 Macros
 
Functions
FunctionsFunctions
Functions
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programming
 
Unit-IV.pptx
Unit-IV.pptxUnit-IV.pptx
Unit-IV.pptx
 
unit_2 (1).pptx
unit_2 (1).pptxunit_2 (1).pptx
unit_2 (1).pptx
 
unit_2.pptx
unit_2.pptxunit_2.pptx
unit_2.pptx
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Function in c program
Function in c programFunction in c program
Function in c program
 
PreProcessorDirective.ppt
PreProcessorDirective.pptPreProcessorDirective.ppt
PreProcessorDirective.ppt
 

More from Dr. Prashant Vats

More from Dr. Prashant Vats (20)

Multiplexers
MultiplexersMultiplexers
Multiplexers
 
C lab programs
C lab programsC lab programs
C lab programs
 
Financial fucntions in ms e xcel
Financial fucntions in ms e xcelFinancial fucntions in ms e xcel
Financial fucntions in ms e xcel
 
4. text functions in excel
4. text functions in excel4. text functions in excel
4. text functions in excel
 
3. lookup functions in excel
3. lookup functions in excel3. lookup functions in excel
3. lookup functions in excel
 
2. date and time function in excel
2. date and time function in excel2. date and time function in excel
2. date and time function in excel
 
1. statistical functions in excel
1. statistical functions in excel1. statistical functions in excel
1. statistical functions in excel
 
3. subtotal function in excel
3. subtotal function in excel3. subtotal function in excel
3. subtotal function in excel
 
2. mathematical functions in excel
2. mathematical functions in excel2. mathematical functions in excel
2. mathematical functions in excel
 
RESOLVING CYBERSQUATTING DISPUTE IN INDIA
RESOLVING CYBERSQUATTING DISPUTE IN INDIARESOLVING CYBERSQUATTING DISPUTE IN INDIA
RESOLVING CYBERSQUATTING DISPUTE IN INDIA
 
India: Meta-Tagging Vis-À-Vis Trade Mark Misuse: An Overview
India: Meta-Tagging Vis-À-Vis Trade Mark Misuse: An OverviewIndia: Meta-Tagging Vis-À-Vis Trade Mark Misuse: An Overview
India: Meta-Tagging Vis-À-Vis Trade Mark Misuse: An Overview
 
Trademark Cases Arise from Meta-Tags, Frames: Disputes Involve Search-Engine ...
Trademark Cases Arise from Meta-Tags, Frames: Disputes Involve Search-Engine ...Trademark Cases Arise from Meta-Tags, Frames: Disputes Involve Search-Engine ...
Trademark Cases Arise from Meta-Tags, Frames: Disputes Involve Search-Engine ...
 
Scheme for Notifying Examiner of Electronic Evidence Under section 79A of the...
Scheme for Notifying Examiner of Electronic Evidence Under section 79A of the...Scheme for Notifying Examiner of Electronic Evidence Under section 79A of the...
Scheme for Notifying Examiner of Electronic Evidence Under section 79A of the...
 
METHODS OF RESOLVING CYBERSQUATTING DISPUTE IN INDIA
METHODS OF RESOLVING CYBERSQUATTING DISPUTE IN INDIAMETHODS OF RESOLVING CYBERSQUATTING DISPUTE IN INDIA
METHODS OF RESOLVING CYBERSQUATTING DISPUTE IN INDIA
 
Computer Software and Related IPR Issues
Computer Software and Related IPR Issues Computer Software and Related IPR Issues
Computer Software and Related IPR Issues
 
Amendments to the Indian Evidence Act, 1872 with respect to IT ACT 2000
Amendments to the Indian Evidence Act, 1872 with respect to IT ACT 2000Amendments to the Indian Evidence Act, 1872 with respect to IT ACT 2000
Amendments to the Indian Evidence Act, 1872 with respect to IT ACT 2000
 
Trademark Issues in cyberspace
Trademark Issues in cyberspace Trademark Issues in cyberspace
Trademark Issues in cyberspace
 
Trade-Related Aspects of Intellectual Property Rights (TRIPS)
Trade-Related Aspects of Intellectual Property Rights (TRIPS)Trade-Related Aspects of Intellectual Property Rights (TRIPS)
Trade-Related Aspects of Intellectual Property Rights (TRIPS)
 
How to Copyright a Website to Protect It under IPR and copyright act
How to Copyright a Website to Protect It under IPR and copyright actHow to Copyright a Website to Protect It under IPR and copyright act
How to Copyright a Website to Protect It under IPR and copyright act
 
International Treaties for protection of IPR
International Treaties for protection of IPRInternational Treaties for protection of IPR
International Treaties for protection of IPR
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Recently uploaded (20)

Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

# And ## operators in c

  • 1. # and ## Operators in C
  • 2. Stringizing operator (#) • This operator causes the corresponding actual argument to be enclosed in double quotation marks. The # operator, which is generally called the stringize operator, turns the argument it precedes into a quoted string. For more on pre-processor directives – refer this Examples : • The following preprocessor turns the line printf(mkstr(geeksforgeeks));into printf(“geeksforgeeks”); • // CPP program to illustrate (#) operator • #include <stdio.h> • #define mkstr(s) #s • int main(void) • { • printf(mkstr(geeksforgeeks)); • return 0; • } • Output: • geeksforgeeks
  • 3. In this program, value of a is replaced by macro. • // CPP program to illustrate (#) operator • #include <iostream> • using namespace std; • #define a 8.3297 • int main() • { • cout << "Value of a is " << a << endl; • return 0; • } • Output: • Value of a is 8.3297
  • 4. This program finds out maximum out of two numbers using macro • // CPP program to illustrate (#) operator • #include <iostream> • using namespace std; • #define MAX(i, j) (((i) > (j)) ? i : j) • int main() • { • int a, b; • a = 250; • b = 25; • cout << "The maximum is " << MAX(a, b) << endl; • return 0; • } • Output: • The maximum is 250
  • 5. Token-pasting operator (##) • Allows tokens used as actual arguments to be concatenated to form other tokens. It is often useful to merge two tokens into one while expanding macros. This is called token pasting or token concatenation. The ‘##’ pre-processing operator performs token pasting. When a macro is expanded, the two tokens on either side of each ‘##’ operator are combined into a single token, which then replaces the ‘##’ and the two original tokens in the macro expansion. Examples : • The preprocessor transforms printf(“%d”, concat(x, y)); into printf(“%d”, xy);
  • 6. The preprocessor transforms printf(“%d”, concat(x, y)); into printf(“%d”, xy); • // CPP program to illustrate (##) operator • #include <stdio.h> • #define concat(a, b) a##b • int main(void) • { • int xy = 30; • printf("%d", concat(x, y)); • return 0; • } • Output: • 30
  • 7. • Application: The ## provides a way to concatenate actual arguments during macro expansion. • If a parameter in the replacement text is adjacent to a ##, the parameter is replaced by the actual argument, the ## and surrounding white space are removed, and the result is re- scanned.
  • 8. # and ## Operators in C ? • In this section we will see what are the Stringize operator(#) and Token Pasting operator(##) in C. The Stringize operator is a preprocessor operator. It sends commands to compiler to convert a token into string. We use this operator at the macro definition. • Using stringize operator we can convert some text into string without using any quotes. • Example • #include<stdio.h> • #define STR_PRINT(x) #x • main() • { • printf(STR_PRINT(This is a string without double quotes)); • } • Output • This is a string without double quotes
  • 9. • The Token Pasting operator is a preprocessor operator. It sends commands to compiler to add or concatenate two tokens into one string. We use this operator at the macro definition. • Example • Live Demo • #include<stdio.h> • #define STR_CONCAT(x, y) x##y • main() • { • printf("%d", STR_CONCAT(20, 50)); • } • Output • 2050