Translate

Array in C++

————————————————————————————
#include <iostream.h> //This is a simple Hello World Program.
int main()
{
cout<<”Hello World”;
return 0;
}
————————————————————————————
//This is a simple Hello World Program.
That line of code is a comment. It is useful for commenting pieces of code. You could do it to remind you about a certain thing in your program.
  • #include <iostream.h>
iostream is the name a Header file.The Header file is very important and is probably used the most out of all the common Header files. The iostream Header file lets you use some of C++ ‘s Important functions like cout and cin. The “.h” is the header file extension. When you include Header files, it is important to include the “<>” signs. The #include code should be typed in before typing in any header files.
  • int main()
This is the main part of the program. Every C++ program MUST have a main function. The Main function is where program execution begins and sometimes ends. The opening curly brace after int main() marks the start of the main function. The closing curly brace marks the end of the main function.we ALWAYS have 2 curly braces in the main function no matter what.The int specifies the type of data to be returned my main().int stands for Integer.
  • cout<<”Hello World”;
cout is used to print out text onto the screen. It is called the Console Output Statement. I like to think of it as c-output…cin and cout are used often in most C++ Programs. cin stands for Console Input. Let me get into detail about what Input and Output are. Input is like the keyboard, where you type in things. The screen is the output, in which you view the typed in text. So the keyboard is the input, the screen is the output.
So after cout we have the “<<” sign. The << operator causes whatever expression is on its right side to be outputted. The opposite way makes the expression inputted, how ever that can only be used for cin or anything similar to it.
I will explain about cin later on in this tutorial.
Ok, so we have cout<<”Hello World”;
Whenever you want text to be outputted onto the console, we type that text in between 2 speech marks. The message “Hello World” is a string. Text enclosed between double quotes are known as strings.
So what about the semicolon? Why do we have that at the end of the line??
This is because C++ statements end with a semicolon.
  • return 0;
This piece of code terminates the main() function and causes it to return the value 0.return 0 is used to terminate the program.
  • }
This ends the code of main()
So now we have gone through a basic C++ Program. Going through this should of given you a good understanding of what is used in a common C++ Program will have.
Now lets go through some more things.

No comments:

Post a Comment