Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why # is required before #include<stdio.h>?

What is the function of #?  

like image 495
machchakumar Avatar asked Jul 10 '10 04:07

machchakumar


People also ask

What is the meaning of why?

English Language Learners Definition of why (Entry 1 of 3) : for what reason or purpose —used to offer a suggestion or to say that a course of action is not necessary —used to express irritation or annoyance

What is your “why” and why is it important?

Using your "why" as a jump start will give you more ideas about your ideal customer groups and how they identify your business. The art of employee recruitment is being able to hire people with the same beliefs, not those who only need the job.

What is the why concept?

The WHY concept first started with Simon Sinek’s “Start with Why.” In his book, Simon explained how the world’s greatest leaders and entrepreneurs inspired people to take actions by understanding and clarifying their organizational purpose - their Why - before leading the way.

What is a why statement?

Generally speaking, the WHY statement is the statement of purposes or beliefs that drive individuals or organizations to the right career path. On the business scale, it’s more often addressed as a mission statement. It sets you aside others as we all have different sources of inspiration behind our actions.


2 Answers

It denotes a preprocessor directive:

One important thing you need to remember is that the C preprocessor is not part of the C compiler.

The C preprocessor uses a different syntax. All directives in the C preprocessor begin with a pound sign (#). In other words, the pound sign denotes the beginning of a preprocessor directive, and it must be the first nonspace character on the line.

# was probably chosen arbitrarily as an otherwise unused character in C syntax. @ would have worked just as well, I presume.

If there wasn't a character denoting it, then there would probably be trouble differentiating between code intended for the preprocessor -- how would you tell whether if (FOO) was meant to be preprocessed or not?

like image 153
Mark Rushakoff Avatar answered Sep 20 '22 11:09

Mark Rushakoff


Because # is the standard prefix for introducing preprocessor statements.

In early C compilers, the pre-processor was a separate program which would handle all the preprocessor statements (similar to the way early C++ "compilers" such as cfront generated C code) and generate C code for the compiler (it may still be a separate program but it may also be just a phase of the compiler nowadays).

The # symbol is just a useful character that can be recognised by the preprocessor and acted upon, such as:

#include <stdio.h>
#if 0
#endif
#pragma treat_warnings_as_errors
#define USE_BUGGY_CODE

and so on.

like image 28
paxdiablo Avatar answered Sep 21 '22 11:09

paxdiablo