Pages

Sunday, February 14, 2010

\ character

Hello,
here we will see the use of standalone '\' or backslash character.

We take it for granted that we use the \ character with an additional character, such as n,a,b,t..etc giving rise to escape sequences, like '\a', '\n', '\b', '\t'...etc, thereby overlooking its standalone use.

Here is a demo of its use!

St1: printf("hello,
St2: world");

At first glance, this might look alright to many, since C is a free form language.
But, upon compilation, the above snippet will give an error, missing terminating ", in both the lines, because, every line requires a closing " for an opening ".

For instance, in algebra, where every opened parenthesis,(, should have a closing parenthesis,).

So! Is there any alternative?

Sure we have, thats where '\' character comes to play. thats what C is about.

The backslash character (\) is used as a continuation character, to bypass a newline.

rewriting the above snippet,

St1: printf("hello, \
St2: world");

o/p: hello, world.

1. The \ character is mainly used in cases where a line,being too long, exceeds the screen limit and you may not want to hinder readability.

2. More specifically, in Macros, when the operation sequence becomes too long.


Have fun with C !

3 comments:

  1. Welcome to the blog world. It is a fantastic hobby.
    Cool fact in your first post! Looking forward to more.
    Check out www.theotherdevdeep.blogspot.com

    ReplyDelete
  2. guys,very nice and the basic facts of C out here so visitors must encourage this blog

    ReplyDelete