1. The tokens passed to macros can be concatenated using operator ## called Token-Pasting operator.
#include <stdio.h>
#include merge(a, b) a##b
int main()
{
printf("%d ", merge(12, 34));
}
Output: 1234
2. The macros can be written in multiple lines using ‘\’. The last line doesn’t need to have ‘\’.
#include <stdio.h>
#define PRINT(i, limit) while (i < limit) \
{ \
printf("Hello "); \
i++; \
}
int main()
{
int i = 0;
PRINT(i, 3);
return 0;
}
Output: Hello Hello Hello
3. There are some standard macros which can be used to print current file (__FILE__), Current Data (__DATE__), Current Time (__TIME__) and Current Line Number (__LINE__)
#include <stdio.h>
int main()
{
printf("Current File :%s\n", __FILE__ );
printf("Current Date :%s\n", __DATE__ );
printf("Current Time :%s\n", __TIME__ );
printf("Line Number :%d\n", __LINE__ );
return 0;
}
Output:
Current File :C:\Users\GfG\Downloads\deleteBST.c
Current Date :Feb 15 2014
Current Time :07:04:25
Line Number :8
#include <stdio.h>
#include merge(a, b) a##b
int main()
{
printf("%d ", merge(12, 34));
}
Output: 1234
2. The macros can be written in multiple lines using ‘\’. The last line doesn’t need to have ‘\’.
#include <stdio.h>
#define PRINT(i, limit) while (i < limit) \
{ \
printf("Hello "); \
i++; \
}
int main()
{
int i = 0;
PRINT(i, 3);
return 0;
}
Output: Hello Hello Hello
3. There are some standard macros which can be used to print current file (__FILE__), Current Data (__DATE__), Current Time (__TIME__) and Current Line Number (__LINE__)
#include <stdio.h>
int main()
{
printf("Current File :%s\n", __FILE__ );
printf("Current Date :%s\n", __DATE__ );
printf("Current Time :%s\n", __TIME__ );
printf("Line Number :%d\n", __LINE__ );
return 0;
}
Output:
Current File :C:\Users\GfG\Downloads\deleteBST.c
Current Date :Feb 15 2014
Current Time :07:04:25
Line Number :8
No comments:
Post a Comment