DEV Community

Cover image for Starting with C++
Zaynul Abedin Miah
Zaynul Abedin Miah

Posted on • Edited on

Starting with C++

Whenever you start a program it has a starting point on C++ the staring point is int main().

Image description

return 0; is an exit point of C++, it means end of the program. iostream is a header file. #include means it's a pre-processing directive. std means standard C++ namespace

Printing Hello World using C++

Image description
Every statement in C++ ends with semi colon (;). cout means you output something on computer. The code behind cout is written on iostream.It is associated with the standard C output stream stdout. The data needed to be displayed on the screen is inserted
in the standard output stream (cout) using the insertion operator(<<)

Preprocessor directive
The preprocessor are directives, which give instructions to the compiler to preprocess some code before actual compilation starts. The directive begins with "#". The actual code is compiled by compiler only.

#include directive
Directive tells the compiler to include the header file in the source code. It's going to preprocess the code written inside<>.

Image description

#define directive
directive tells the compiler to create a symbolic constants. The symbolic constant is called macro.

All subsequent occurrences of macro in that source code will be replaced by replacement text before the program is compiled.

Image description

Identifiers
Both identifiers and variables are the names allotted by users to particular entity in a program. The identifier is only used to identify an entity uniquely in a program at the time of execution where variable is a name given to a memory location, that is used to hold a value. Identify is just the name whereas concept of variable means the name and bucket as well. Identify is used to give name to the bucket.

Image description

Keywords
Keywords are the word that have special meaning for the compiler. These keywords cannot be used as identifiers. C++ has about 95 reserved words.

Image description

Main function
Main is not a keyword of C/C++. Main is not predefined but it is predeclared. In C++, your code is linked against small runtime library that constitutes that constitutes the true starting point of your program. It's this small library called function main--it is hardcoded to do so. Your code runs because you supply the code inside main, also called function definition.

Image description

Namespace
Naming conflicts can arise if you use multiple 3rd party libraries in same program. Namespaces are used to resolve naming conflicts. std is namespace for standard C++ namespace. Writing std::cout will tell the compiler to use "cout" from standard namespace.

Image description

Comments
Comment is a text to annotate code for future references. Comment is ignored by compiler but is useful for programmers. You can use comments in testing to make certain lines of code inactive. We can write single/ multi line comment in C++ Program.

Image description

Top comments (0)