what is # symbol in C?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zweety
    New Member
    • Jul 2007
    • 2

    what is # symbol in C?

    what is the function of # symbol in C.
    for eg:# include<stdio.h >.this statement is used for linking the i/p nd o/p fns in the pgm to the header file.is this # is the directive.someb ody said to me that # is assembler directive.can anyone explain what an assembler directive is?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by zweety
    what is the function of # symbol in C.
    for eg:# include<stdio.h >.this statement is used for linking the i/p nd o/p fns in the pgm to the header file.is this # is the directive.someb ody said to me that # is assembler directive.can anyone explain what an assembler directive is?
    The '#' introduces a so called 'pp-token', i.e. a 'preprocessor token'. It has nothing
    to do with assembly or whatever. Within a preprocessor directive this character
    may be the catenation operator or the stringize operator. It's all preprocessor
    stuff which by itself has nothing to do with the C(++) language itself.

    kind regards,

    Jos

    ps. what is "i/p nd o/p fns"?

    Comment

    • scruggsy
      New Member
      • Mar 2007
      • 147

      #3
      Originally posted by JosAH
      The '#' introduces a so called 'pp-token', i.e. a 'preprocessor token'. It has nothing
      to do with assembly or whatever. Within a preprocessor directive this character
      may be the catenation operator or the stringize operator. It's all preprocessor
      stuff which by itself has nothing to do with the C(++) language itself.

      kind regards,

      Jos

      ps. what is "i/p nd o/p fns"?
      I think that translates to "i/o functions".

      To clarify a little bit on what Jos said, preprocessor directives are a way of communicating with the compiler while it's building your code. Like telling it what other source files to include, or defining macros (text substitution), or telling it to ignore parts of the code under certain conditions. They are not part of the C++ language.

      Comment

      • tburger
        New Member
        • Jul 2007
        • 58

        #4
        Outside of indicating which source files / libraries to include, the "#" character can also be used to define a "global constant"...

        example:

        #define PI 3.145

        Anywhere you use "PI" in your code, the compiler will replace it with the value 3.145.

        It's another way to set a constant in C. It becomes quite handy when "PI" comes up in your code many times. Instead of having to find and replace 10 "PI" values, all you have to do is change the #define value and the compiler will do it for you...

        Enjoy

        Tom

        Comment

        • epyk
          New Member
          • Jul 2007
          • 7

          #5
          ive know # as a compiler directive, it allows you to use the compiler to edit, add or select code during compile time. you can prolly find documentation on whatever compiler you are using

          Comment

          Working...