ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

How to Write a Line of Code in C++ Programming Language and Some Other Basic Computer Programming Concepts

Updated on March 15, 2020
CELEBSFAN78 profile image

Ara is a Journalism graduate from California State University Northridge who is looking to always explore his writing opportunities.

This Information Is Particularly Useful For Computer Science Students

For those of you that are Computer Science majors you will find this article a useful start in the development of your knowledge. I’d like to take the opportunity to say that I’ll be writing tutorials for computer programming for those that are interested in resources such as this. This one will address how to write a simple program for the C++ programming language. And the next part of this article will discuss some of the basic concepts in computer programming.

In C++ Details Really Matter

Writing a simple program does not take many steps actually. First of all since this is a simple demonstration for how to do this, there won’t be too many lines of written code. For the more complex tutorials that may be coming in the future, there will be more lines of code and a more detailed explanation. For now, I just want to introduce those new to programming that C++ like other programming languages is case sensitive. Details really matter in computer science. For example, the character a is different from the character A. One of these is an uppercase letter and the other one is a lowercase letter.

A C++ Photo

A Basic Line Of Code In C++ And Explanation of the Functions

Okay, now since that is done, let me say that there are a few statements that you must have before you start coding.

#include <iostream>

#include <cstdlib>

using namespace std;

Include iostream tag in C++ is designed so that you can type input and have output printed onto the screen. Then you can have comments. Comments in a program explain to the persons who are reading the program what is going on. It makes others follow along easier. There are single line comments and multi line comments. Single line comments have a format like this:// comments. Here is a simple one line program in C++:

#include <iostream>

#include <cstdlib>

using namespace std;

int main()


cout << “This demonstrates what goes on in a C++ program.”;


return 0;


The cout statement allows the end user or the person typing the program to enable the compiler to read output. The system pause command prevents the program from aborting abruptly and you can see what kind of output will be displayed on the screen. The return statement must be in every C++ program. There are no exceptions. The opening curly brace is there to tell the compiler that the main function is now running. The closing curly brace tells the compiler that this marks the end of the function. All functions in C++ must have opening and closing curly braces to indicate the beginning and end of the main function.

As you see, this is just a basic program. The more complex programs will have more functions and more lines of code.

Programming Language Cloud

In Computer Science, there are several programming languages as this cloud shows. Java is also included in the most famous programming languages as well as C# and C++.
In Computer Science, there are several programming languages as this cloud shows. Java is also included in the most famous programming languages as well as C# and C++.

The Purpose of Pseudocode and Comments In Computer Science

In computer programming, there are certain steps that every programmer should complete before they actually start the writing or coding process of the program. One of the first things that I suggest that you do is write down what is called pseudocode. Pseudocode is basically short phrases written in English and these phrases describe the algorithm of the program that you are working on. An algorithm is a series of instructions that are written which enable the programmer to complete a specific task or to solve a problem in a finite amount of time. Some programs will take longer than others to complete depending upon their complexity. Pseudocode makes everything easier because when you write pseudocode before you start coding, you have a better general idea of what steps to take to complete the program. I would like to consider pseudocode as the blueprint of the program. When you start writing the pseudocode, you can use the symbol /*. And then, when you are finished with that part, you can end the pseudocode section with the symbol */. Pseudocode and comments are ignored by the compiler.

Writing comments during the coding process of the program gives other programmers a better idea of where the program is going. It helps make your program more readable. Programmers can then understand what you are doing. When a programmer is busy coding and writing the program, it is their responsibility to be able to come up with an algorithm that solves the task correctly and efficiently. Just compiling the program is not good enough. You also must run the program to make sure that it displays the output that you would like to see on the screen. If you run the program and then you see that it does not display the correct output on the screen, this is where a logic error can occur. Getting the program to run efficiently and display the correct output is very challenging because when you write the program, you have to have a solid general idea of the concepts that you are using to complete the task. And it takes lots of practice to learn the concepts in C++, Java or any other programming language. In other words, to say this in more simple language, in order for your program to be complete, it must compile properly and be free of any syntax errors and it must also run correctly and display the proper output on the screen. Do not think that just because your program compiles correctly then it is done and complete. Your program must do both steps just described. Every method or function as they are known in C++ must have a main function.


How Variables Work and How to Declare Them

After you have declared the main function in the program, you can write a comment saying that you want to declare the variables. A variable is something that has a name and that it describes a certain value. But first you must assign a specific data type to the variable. Some examples of variable declarations are:

int 56;

double 50.00;

float 34.5;

char letter;

A variable can always be changed during the execution of a program unless you decide to declare the variable as a named constant. If you decide to declare the variable as a named constant, then it cannot be changed during the execution of a program. A variable name cannot begin with any numbers, special characters such as a dollar sign, number sign or exclamation point. A variable name also cannot have one of the reserved key words of the programming language such as while, return or do-while. And another thing to remember is that when you declare a variable make sure to do it using lowercase letters.

When you declare your variables in your program and assign values to them, make sure that you write the value after the name of the data type. For example, you cannot declare a variable like this: 25 = int;

If you do it that way, you will get a syntax error. So make sure to declare the variable and assign the value like this instead: int = 25;

And as always, do not forget to put the semicolon after the variable has been declared and assigned the value. A lot of programmers make this mistake. But as you get better at programming, you will make fewer errors. Remember that it takes patience and lots of practice. Everyone makes mistakes especially in coding. The key to success in Computer Science is to be patient while coding! Good luck!

© 2017 Ara Vahanian


    0 of 8192 characters used
    Post Comment
    • CELEBSFAN78 profile imageAUTHOR

      Ara Vahanian 

      2 years ago from LOS ANGELES

      Thank you very much for your comment on this. I've taken quite a few computer science courses so I have a pretty good general idea of the basic concepts.

    • profile image


      2 years ago

      exactly on the point,good tutorials


    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at:

    Show Details
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the or domains, for performance and efficiency reasons. (Privacy Policy)
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
    ClickscoThis is a data management platform studying reader behavior (Privacy Policy)