Day#39 'C' Coding Challenge

Day#39 'C' Coding Challenge

What are preprocessor operators in C?

Following are the preprocessor operators in C:
  • Stringizing Operator (#)
  • Token-Pasting Operator (##)
  • Macro Continuation Operator (/)
Stringizing Operator (#):

When this parameter is used along with Macro in it's parameter definition, it converts that parameter into string. Example as below:

#include<stdio.h>

#define wesbite_name(name) #name 

int main()
{
printf("%s",wesbite_name(Embeddeddesignblog));
return 0;
}

Token-Pasting Operator (##):

Token pasting helps to combine parameters in a Macro. For example, in the below code, pagecount and n are combined using token-pasting. They are seen as single parameter by the compiler.

#include <stdio.h>

#define website_pages(n) printf ("pagecount" #n " = %d", pagecount##n)

int main() 
{
   int pagecount_1 = 5;
   website_pages(_1);
   return 0;
}

Macro Continuation Operator (/):

A macro extends over a single line. If we want to write the same macro extending over two lines, '/' need to be used.

#define website_pages(n) /
printf ("pagecount" #n " = %d", pagecount##n)

Post a Comment

0 Comments