-3

Possible Duplicate:
concatenation of two string literals

Case 1 "hello" "world" (NO ERROR)

Case 2 "hello"+"world" (ERROR)

I know that the + operator must atleat have one of its operand as string type,not string literal.

Thing is,both of the cases doesnt make sense,since we can include it into a single literal !

Why is Case 1 allowed then!

Community
  • 1
  • 1
Anirudha
  • 32,393
  • 7
  • 68
  • 89

2 Answers2

5

Case 1 is allowed because C++ basically considers adjacent literals to be the same literal, i.e. the code "hello" "world" is transformed into "helloworld" early on in the parsing.

unwind
  • 391,730
  • 64
  • 469
  • 606
0

Case 1, as you call it, is a convenient way to let string constants span several lines or be broken up into easily identified parts.

It's there to make your life easier.

Assuming that + should have the same semantics when used with string constants is a mistake. Especially in C, where string isn't an available type.

HonkyTonk
  • 1,961
  • 11
  • 11