answersLogoWhite

0

Why you use hash in c plus plus?

Updated: 8/9/2023
User Avatar

Wiki User

12y ago

Best Answer

#define is a pre-compiler directive which is used to define a macro. All occurrences of the defined macro within your source code are replaced by the macro definition prior to compilation. In other words, your code is altered to produce an intermediate file which is actually compiled, just as if you'd copy/pasted the macro definition throughout your code. However, the end result is that the compiler cannot identify any problems within your macros since they will no longer exist in the intermediate file. Macros are not type safe, thus they are generally frowned upon, especially when they are used to define complex functions. However, correct usage of macros can greatly simplify your code and ultimately permit the compiler to build different versions of your code, depending upon which definitions you define. For instance, you will typically use slightly different versions of some functions depending on whether you are building a debug or release version of your code, and will typically #define DEBUG for debug builds. You can also cater for cross-platform coding by filtering platform-specific functions using macro definitions. You alter the type of the build simply by defining the appropriate definitions, either within the code itself (using #define), or via the compiler's pre-processing command line switches, or a makefile script.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

The # symbol defines pre-processor instructions. For example:

#include name_of_header.hpp;

tells the processor that the program will include a header which is externally written.

Another example is:

#define NameOfStructure name_of;

This means that, where I would have declared something 'NameOfStructure,' I can now use 'name_of' instead.

This example is a typedef which allows the declaration of a given data variable/type to be given a different name, and allows (but is not limited to) excessively long names to be shortened, but keeps the code self documenting.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why you use hash in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

In C plus plus what sign do all preprocessor directives start with?

all preprocessor directives start with #(hash) symbol in both c & c++


How do you use conioh header in c plus plus?

just as you do it in C.


Can you use c in c plus plus without using class and object?

Sure.


How do you enter a sentence as input in c plus plus?

Use the C++ getline() function from the standard library.


What is use of keyword extra in c plus plus programming?

Nothing.

Related questions

In C plus plus what sign do all preprocessor directives start with?

all preprocessor directives start with #(hash) symbol in both c & c++


Why you hash in c language?

ANSWERThe reasons to use hashing in C are the same as in any language. A hash value is used to reduce a value from a complex form into a simpler form, to simplify operations such as searches.


How the turbo c plus plus use in the computer?

How the turbo c plus plus use what in the computer.


How do you use conioh header in c plus plus?

just as you do it in C.


Can you use c plus plus in windosh vista?

Only if you have a C++ compiler.


Which is best C or C plus plus?

depends what you use it for. c++ = object oriented c = not object oriented


User defined data type in c plus plus?

Use "typedef" : both in C and C++.


How do we add the C plus plus category in Netbeans?

To use C++ in Netbeans you will need a C++ compiler.


Can you use c in c plus plus without using class and object?

Sure.


What is the use of c plus plus in banks?

Programming language.


Why are there 2 plus sign in c plus plus and Why not a single plus sign?

In C and in C++, the ++ operator means to increment. C++ was intended to be the next version, i.e. the incremental next step, of C, hence the use of the ++ operator.


How do you enter a sentence as input in c plus plus?

Use the C++ getline() function from the standard library.