C++ Basics

Cout is a magical tool.

Ahmed Yasin
6 min readJun 25, 2020

Today I am going to tell you about cout function in C plus plus.What role IDE preforms in programmers’ life and understand the concept of variables. Learn about cout function in detail to use cout function at advance level. I will show you by solving problem 3.5. At the end I will assign task to those readers which are beginners in C++. I will explain you the importance of practicing and share my experience with you. I believe it would be worth reading story.

IDE (Integrated Development Environment)

What is IDE ?

IDE is a software application. It name shows. A developing tools integrated in an environment. IDE consist of source code and many other tools to build or create an other program. There are variety of IDE software brands. We know computer is a dumb machine. It don’t understand anything until we do not try to communicate it in a same language. Computer understands only machine language which is binary language. It looks like this(001011) but we can barely understand this language so we use IDE software which plays role as a translator between computer and human. There are some names of different IDE. Names I mentioned below.

  • Dev C++
  • Visual studio code
  • Xcode
  • Microsoft visual studio

If you are beginner than I prefer you to use Dev C++.

Programmer first select language in which he/she start writing his/her program. Most of programmers start with C++ language. Basically it is basic language to make any program. It helps to understand computer from zero level.

“Stronger base never let you down, No matter how hard storm in your town.’’

Gradually when you learn c++ language than other advance computer languages you will learn so quicker and more better. Names of some computer languages I have shared with you.

  • Pythan
  • Java script
  • PHP
  • C++

Variables

What are variables ?

Variables are one of the most important concept in computer languages. Lets read its name again Vari-able or vary able which means variation is able. In simple words we can change the value of variables. In primary schools we have learnt the concept of variable and constants in Mathematics. The concept was very simple. Variable value can change but constant is constant that is never gonna change.

Example from physics :

Lets take an example from Physics. So, suppose we have a ball. Weight of a ball is 300 grams on the Earth but if you check weight of the same ball on moon that will change and come to 49.60 grams. It means weight changes so weight is a variable but if we concern with mass( Number of particles ) of ball than that will remain constant. Which means no change in the value of mass.

Example from mathematics :

Lets take an old example from Mathematics. So, we have an expression x=1+3 . Where x is variable x value can change when we add 1 and 3. where 1 and 3 themselves are constants.

Example from computer :

Now in computer language variable concept is same. We first define or declared variables in a IDE. Defining and declaring are same terms you don’t need to confuse between these two terms. When we declare any variable in program it stores in RAM (Random access memory). We mostly know this is temporary storage memory which means it doesn’t stores data permanently. If data become permanent that will be permanent data which means constant but right now we are discussing variables and variables changes that is way they stores in RAM. There are some types of variables. I am sharing two of them below.

  • Predefined variables

There are some variables which are already defined in standard libraries of computer languages . Which means some variables are already defined and built in computer dictionary. So whenever we use them they perform some specific function for which they defined already.

Example :

Variable cout predefined to print something on screen.

Variable cin predefined to take any input from user and so on.

  • User-defined variables

These functions are define or declare by the use himself/herself. We declare variables according to his program.

Cout function

What is cout ?

I think the most useful, basic, and best variable in standard library is cout variable. It pronounce (See out). Cout stands for common output. Basically it is output stream. It print anything on the screen in output. You can print any string ( Group of words ) ,any number or pattern on terminal. We use cout function with insertion operators << .If you want to print some string in output than use “ ” inverted comas and write your string between inverted comas.

Note : Always Add semicolon ; at the end of each line in you code. Its is called terminator. It terminates line.

Now lets see the syntax of cout.

(First step) cout (Second step) << (Third step) “Hello world” (Forth step) ;

or

cout << “ Hello world ” ;

This line print Hello world in the output now we can do this in other way also but first understand the note given below.

Note : Insertion operators << are use to separate items in output stream or cout

Now lets see the syntax in other way.

(First step) cout (Second step) << (Third step) “Hello ” (Forth step) << (Fifth step) “world” (Forth step) ;

or

cout << “Hello ”<< “world” ;

This line also print Hello world in the output.

Importance of practicing

Why practice ?

Practice is very important in any field. All fields demands practice, hard work, time and interest. Whatever you are doing make sure you have great interest about that. If you do any work without interest you can never be best in that thing so your interest matters a lot. When you are interesting in doing something you will try to find every possible way to do that and give your best and such interest will force you to do hard work and you will start spending time on that thing. In-case if you lose once you won’t give up and you will do that again and again which is called practicing that leads you to success.

Interest is a door , Time is a key where practicing is an effort to open the door and behind the door there is a success which is reward.

Never lose your heart keep practicing and give your best. You will reach your destination one day. I used word practicing because I don’t want you to copy and paste others efforts (codes). You won’t learn anything by doing this. Make sure you try to solve most of problems by yourself. You just need to understand the concept very intentionally and then try to solve problems by yourself. If still there is some problems than you can ask to you teacher or your seniors or your some shining classmates or you can just read about that from Google or elsewhere but try to learn not just copy, paste, leave and run.

“ Practice makes the man perfect ”

Task 3.5

Lets solve task 3.5. but first understand the statement.

Task 3.5

Statement :

It states take that print the given pattern in output by using simple cout statement.

*
* *
* * *
* * * *
* * * * *

Solution :

(First step )

First include IO stream(input/output stream) and than use standard library reference in which cout variable is predefined. You can not use output stream without adding header file or std(standard library).

#inlcude <iostream>

using namespace std;

(Second step)

Secondly you will make a function which will be main function and its time will be integer. For now this much information is enough so lets work with this.

int main ()

{

}

(Third step)

Now we will write code between curly brackets {}

cout << “*” ;

cout << “* *” ;

cout << “* * *” ;

cout << “* * * * ” ;

cout << “* * * * *” ;

Now I am doing to combine work which I wrote in previous three steps so here we go.

#inlcude <iostream>

using namespace std;

int main ()

{

cout << “*” ;

cout << “* *” ;

cout << “* * *” ;

cout << “* * * * ” ;

cout << “* * * * *” ;

}

Now run this program.

Congratulations we just nailed it. We completed assigned task.

Task for beginners in C++

Well this task is assign for those readers which are new in learning c++

You task is print the given pattern by using cout statement :

        *
* * *
* * * * *
* * * * * * *
* * * * * * * * *

Video tutorials

If you wanna watch tutorial in which I solve these tasks too. Than you can watch them on Youtube the link is given below.

https://www.youtube.com/channel/UC-gDcN99rYbeyH1oKsoPM3A

--

--

Ahmed Yasin
Ahmed Yasin

Written by Ahmed Yasin

Youtuber / Content Writer / C++ /Learning Java/ https://www.youtube.com/channel/UC-gDcN99rYbeyH1oKsoPM3A Instagram : belongs_to_mars

No responses yet