
- Forum
- Programming Talk
- C and C++
- New Notation
New Notation
This is a discussion on New Notation within the C and C++ forums, part of the Programming Talk category; I know that # is used for preprocessor directive in C programming language. But recently I saw in my friend’s ...
-
New Notation
I know that # is used for preprocessor directive in C programming language. But recently I saw in my friend’s code a new operator with notation as ## but I could not understand what it meant and the usage of the same. Can some one share your experience of this operator ## which would help all members to learn about this new notation.
-
06-04-2007, 12:44 AM #2
- Join Date
- May 2007
- Answers
- 12
The # and ## operators are used with the #define macro. Using # causes the first argument after the # to be returned as a string in quotes. Using ## concatenates what's before the ## with what's after it.
--------------------------------------------------------
#define to_string( s ) # s
will make the compiler turn this command
cout << to_string( Hello World! ) << endl;
into cout << "Hello World!" << endl;
---------------------------------------------
Here is an example of the ## command:
#define concatenate( x, y ) x ## y
...
int xy = 10;
cout << concatenate( x, y ) << endl;
into
cout << xy << endl;
-
It was a great explanation on the notation #. Can you give some example in C programming language of this notation #. This would help me to learn more deep about this notation usage.
-
06-07-2007, 12:29 AM #4
- Join Date
- May 2007
- Answers
- 12
#define to_string( s ) # s
#include <iostream.h>
void main(void){
cout << to_string( string wiout quotes ) << endl;
// cout requires quoted string and using macro to_string will return the same
}
------------------------------------------------
#define concatenate( x, y ) x ## y
#include <iostream.h>
void main(void){
in ab = 20;
cout << "The your age is " << concatenate(a,b)<<endl;
// ab is variable and u want to print is value
//the concatinate macro just do the same and result will be ab which is a
//varibale declared by you as int
// remember output by cancatinate is not a quoted string and will not be
// string in any case it will be just concatinated input values
if any confusion email me in detail at maksunn@gmail.com
}
-
Sponsored Ads

Reply With Quote





