Starting with Programming
To start with programming you should have compiler in your computer , you can download free open-source cross-platform IDE that supports multiple compilers such as codeblocks . I have provided the link below to download codeblocks and steps to install it , please check out :
http://www.codeblocks.org/downloads
Download the binary release for your operating platform ( Windows 2000/XP/Vista/7 ) and install it . If during installation no compiler is detected by your pc then download the installer with GCC Compiler, e.g., codeblocks-13.12mingw-setup.exe (98 MB) (which includes MinGW's GNU GCC compiler and GNU GDB debugger) .
After installation open codeblocks press Ctrl+Shift+N to open new file then first save it using keys Ctrl+S so that if you make any mistake small red square will be shown in the left side of the respective line . And use extension .cpp while saving the program .
Ex- my.cpp ( you can give any name but extension should be .cpp )
* Let's start with a simple program which display My first program as output :
after coding press F9 to get your output (if your program has no errors , if there are some errors it will get display below the screen along with the line number ) , lets see the output for this program :
This black screen (like cmd screen) represent successful operation and the output is printed on the top line.
Let's understand how it works line by line :
1. #include<iostream>
2. using namespace std;
- In our code, the line using namespace std; tells the compiler to use the std (standard) namespace.
- The std namespace includes features of the C++ Standard Library.
3. int main( )
- int is a keyword .
- Always remember program execution begins with the main function, int main( ) .
- The entry point of every C++ program is main(), irrespective of what the program does.
- Curly brackets { } indicate the beginning and end of a function, which can also be called the function's body. The information inside the brackets indicates what the function does when executed .
- This line display the output in the screen .
- Here cout ( keyword ) is standard output stream .
- In C++, streams are used to perform input and output operations.
- In most program environments, the standard default output destination is the screen. In C++, cout is the stream object used to access it.
- cout is used in combination with the insertion operator. Write the insertion operator as << to insert the data that comes after it into the stream that comes before.
- To print anything in C++ use cout with insertion operator ( << ) and write anything in double quotes (" ") and terminate the line with semicolon .
- In C++, the semicolon is used to terminate a statement. Each statement must end with a semicolon. It indicates the end of one logical expression.
- The C++ compiler ignores blank lines , so you can have as many you want.
- In general, blank lines serve to improve the code's readability and structure.
- Whitespace, such as spaces, tabs, and newlines, is also ignored, although it is used to enhance the program's visual attractiveness.
- return is a keyword.
- The last instruction in the program is the return statement. The line return 0; terminates the main() function and causes it to return the value 0 to the calling proces .
- If the return statement is left off, the C++ compiler implicitly inserts "return 0;" to the end of the main() function.
Comments
Post a Comment