Hi ! Friends Welcome to Education Forums

Please Get Registered in these Forums and Get Complete Information regarding your Interests ,If You Wanna Ask Any Questions or Doubts On Any Topic.
Then Please Post Your Questions In Correct Section For Getting Perfect Solutions From Our Registered User's .
Thanks For Viewing Our Forums.
(This Notification wil Remove After Login Or Registration !!)


 
Thread Rating:
  • 2 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ -Tutorial #1-
11-21-2011, 07:59 AM
Post: #1
C++ Tutorial #1 ~ The Basics


Ok guys, I decided to make a tutorial over the basics of C++. Though i am still learning C++ myself, i have a good understanding of what I'm about to talk about.






First off, we'll start off with the famous program, "Hello, World!". I will explain the meaning of the different parts of this program and what they do.

Code:
//ouput "Hello, World to the screen"
#include <iostream>

using namespace std;

int main(){

    cout << "Hello, World!" << endl;

   return 0;
}

That is the "Hello, World!" program, one of the most basic programs you can make in C++, all it does is output the text "Hello, World!" to the console.


I'll Break it down into different parts.


//ouput "Hello, World" to the screen
This is a comment. Comments are ignored by the compiler and used for the benefit of the programmer. Comments can be very useful when writing large programs. It is good practice to use comments through out your code explaining what a specific part of code does. This will avoid confusion if you ever decide to come back to your code in the future.

#include <iostream>
This line tells the preprocessor to include the iostream standard file, that's not something to get into right at the beginning.

using namespace std;
This line of code is telling to include the names from the standard library. Some names from the standard library include cout, cin, endl, and others. Using this would allow you to use those without having to declare the scope.

int main()
This line is declaring a function, int being the return type of the function and main being the name of the function. The main function is the function all C++ programs start for in the beginning. A function can be divided into four main parts


cout << "Hello, World!" << endl;
I will break this line up into different parts.
cout - part of standard library, it is the standard output stream.
<< - The output operator, takes what is on it's right side and outputs it to the screen.
"Hello. World!" - A string literal, it is the text that will appear on the screen
endl - part of the standard library, used to end the current line of output on the console.
; - signifies the end of a statement


return 0;
The return value of function main. This is commonly used in programs and tells the system that the program was executed successfully. Any non-zero number it returns signifies failure to run successfully.









Alright guys, that's it for this tutorial. I know i went kind of in depth on stuff for a basic tutorial, but that's fine. I'll try to put up part 2 as soon as i can, but with school and all it won't be easy. Leave a reply if i missed anything or just to say thanks!


[Image: moRo0.jpg]
Reply
11-21-2011, 05:49 PM
Post: #2
Very nice tutorial, nice share :)
Reply


Forum Jump:


User(s) browsing this thread: 1 Guest(s)