CrazyEngineers Archive
Old, but evergreen and popular discussions on CrazyEngineers, presented to you in read-only mode.
@nerdy_me • 20 May, 2011

Though single "#" is used to concatenate two strings even in d macros..i.e.

try in dev compiler ::

#include

#include

#define delhi(s1,s2) s1#s2

using namespace std;

main()

{

char sh[]=delhi("hello","ceans");

printf("%s",sh);

system("pause");

}

but I found on net that ## is used to concatenate two strings which is wrong as # is concatenating the strings?

@nerdy_me • 20 May, 2011 Though single "#" is used to concatenate two strings even in d macros..i.e.
try in dev compiler ::
#include<cstdio>
#include<conio.h>
#define delhi(s1,s2) s1#s2
using namespace std;
main()
{
char sh[]=delhi("hello","ceans");
printf("%s",sh);
system("pause");
}
but I found on net that ## is used to concatenate two strings which is wrong as # is concatenating the strings?
@synergynext • 21 May, 2011 the # symbol distinguishes the Pre-processor commands. for eg to include library, define a macro etc
where did u see ##? kindly share the link
@nerdy_me • 22 May, 2011 This question was asked by external in viva.I was searching its answer but couldn't find.😐😐
@nerdy_me • 22 May, 2011 I don't know about "##" .Is it signifies something in C language or it has no use?
@vik001ind • 22 May, 2011 There is a serious flaw in your concept. When you run your program, the output is --> hello"ceans" & not helloceans.
When we use a preprocessor directive like this one #define A a, every occurrence of 'A' is replaced with 'a' during preprocessing.
The significance of # before the parameter is that when preprocessing occurs, it is expanded into a quoted string with the parameter replaced by actual argument.
Try a simple example,
#include<stdio.h>
#define print(s2) printf(#s2)
void main()
{
print(hi);
}
It will print hi as print(hi) is preprocessed as printf("hi"). Similarly, delhi("hello","ceans") becomes "hello"""ceans"". The third & forth double quote gets nullified. Now, the combined expression is sh[]="hello"ceans"" that's why the output is hello"ceans".

In case of ##, the situation is completely different. In this case the parameters are simply concatenated.

Try this,
#include<stdio.h>
#define F(a,b) a##b

void main()
{
      int x =2,xy=4;
       printf("%d",F(x,y));
}
The output will clarify the role of ##.
@vinsocorp • 24 May, 2011 ## is used to concatenate as like
ex: a=4,b=5,ab=6;
a##b compiler read as ab..
if you print the result its takes the varianle as ab;and its produces 6........
@Vinay Mishra • 26 Dec, 2019 • 3 likes

Don't be confuse. Let me clear it..

'##' is known as Token-pasting operator.

As per name, this operator is used to paste the tokens. This operator works to allow any token as a argument and concatenate to form other tokens. It is a pre-processing event which can paste tokens.

Simple difference in '#' and '##' is:

• # : It is known as 'Stringize operator'. It is used to convert a token into string. By this operator we can convert some text into string without using and quotes.

• ## : It can be defined by simple example i.e This operator converts-

printf(“%d”, concat(x, y));

Into

printf“%d”, xy);

Hope you got it!

@Divisha Madupalli • 26 Dec, 2019 • 2 likes

## is used for concatenation like if you have 

X=5,y=6

And you print X##y then it prints 56.

## is a preprocessor operator which is mostly used with the  # define in C .


# define sum(x,y) x##y .

It is written like this .

@Teja Reddy • 26 Dec, 2019 • 2 likes

The operator ## which is used to concatenate two strings or arguments by leaving no blank spaces between them 

example #define demo(a,b) a##b

                 demo(c,out)<<"YOYO";


@Mohana Chandra • 26 Dec, 2019 • 1 like

## is called "Token-Pasting operator.

Tokens is the smallest units of a program. ## is used to concate/merge two tokens ,which are actual parameters ,to form a New token. 

As ## concates the tokens ,this process also known as Token concatenation.

#define concat (x,y) x##y

int main ()

{     int ab=20;

printf ("%d",concat (a,b));

}

The above code snippet gives the output 20


@Kavya Burramolla • 27 Dec, 2019 • 1 like

## operator in C programming generally concatenates two tokens and pastes the single token. Hence called the Token pasting operator. For example : let one token be A whose value is 1 and other be B whose value is 2, then using ##operator as A##B, it results in the value of 12. Note that the resulted single token can be a variable, number.

While the #operator is to convert a text or a token into a string. Hence called stringise operator. For example: let a token A be the value of tree. Then #A will result in “tree”, without using any extra quotation marks. 

@Noothan Kumar • 24 Jan, 2020 • 1 like

Any programming language consists of a set of instructions(pre-written) called library functions. # means that you are essentially telling the compiler to put whatever follows into the program.

to put whatever follows into the program.

#include<stdio.h> means that i am asking for the standard input output functions(printf and scanf) in my program.

@Teja Reddy • 25 Feb, 2020

C language is used to develop system applications that forms major portion of operating systems such as Windows, UNIX and Linux. Operating systems, C compiler and all UNIX application programs are written in C language.

  • Database systems
  • Graphics packages
  • Word processors
  • Spread sheets
  • Operating system development
  • Compilers and Assemblers
  • Network drivers
  • Interpreters
@supriya VN gowda • 25 Feb, 2020

# is used to include all the necessary libraries required by your program and each library includes set of functions. #include<stdio.h> Library will have printf() like functions. 

## is used along with#def and ## is used to concatenate two strings and these operator is known as token pasting operator. It is a preprocessor operator. These can be used with # define diff(a, b) a##b.

8.7k views

Related Posts

@Ankita Katdare · May 16, 2013

Panasonic India has today launched its new 'out of the world' smartphone called the Panasonic P51 at Rs. 26,900/-. If you're someone who keeps an eye for the gadget-related news,...
1.7k views

@Kaustubh Katdare · Nov 4, 2010

Hello CEans, Here's a quick guide on setting up BSNL 3G Data Card in uBuntu 10.10 - 1. The Easy Way - Plug -in your data card into your laptop's...
1.7k views

@Sarathkumar Chandrasekaran · Dec 21, 2013

This question may look bad but I want to know the reason behind it.I tried to connect the net using teathering and when i use the 2G network and open...
1.2k views

@P.tejaswi · Aug 22, 2008

I am really undecided as to whether go for any coaching like GRE or CAT which many of my friends are going.i am in 5th semester now and i want...
7.6k views

@Kaustubh Katdare · Feb 6, 2014

Was going through Moto G specs and found that it has a hall effect sensor. Just read about and remembered the 'hall effect' I had studied during my engineering course....
30.6k views