C++ Programming Languages With / Series 1

What will we learn?
a

  • Introduction to Programming


Requirements:

  • Notepad+
  • Windows Operating System
  • Dev-C++

Program download link : Download


Why is it dev-c++?

  • BloodShed is an open source software produced by company .
  • Compatible with Windows operating systems.
  • Shows different commands in different colors and makes it easy to write code.
  • Supports both 'C' and 'C++' languages.
  • It has a size of 23-30 MB. Easy to download and install quickly.

Difficulty Level:

  • Normal Level


Let's Start the Course :

C ++ Language Writing and Punctuation Rules

As with any language , there are some spelling and punctuation rules in C++. If you don't follow these rules , you'll get a mistake. Below are the important spelling and punctuation rules.

Semicolon ;

In C++ and other C-based languages , semicolons(;) are placed at the end of each command.

init x=0, y, top=0;
x=x+1;
top=top+x;

A semicolon indicates that a command is finished and that another command can start. For example, you can type 'cout<< <' and 'cin>>' commands side by side , or you can type 'cout < <' at the bottom.

cout<<"YourAge:";  cin>>age;

or

cout<<"YourAge:";
cin>>age;

For better readability of the program , more than one command is usually not written on a line. Single command is preferred on each line.

Forgetting a semicolon is one of the most common mistakes in C++.

Nice(Fancy)Braces {...} and block concept:

The C++ language consists of blocks. Set the Start and end position of blocks , also called Nice or fancy parentheses. For example, our main program ' main()' starts with ({) and ends with (}).

{...} the commands in the marks are called blocks. A block is a collection of commands that are assembled for a particular purpose, and they ensure that the corresponding code is distinguished. Blocks also help make the program more readable .

int main ( )
{ //Block Start
command1
command2
command3
}//Block End

Each opening parenthesis or block must be closed. If you don't turn it off , you'll get an error , which is another very common error.Therefore , if you open a beautiful parenthesis, be sure to close it immediately , then close it without writing the code into it.

Space Character

The space characters for the C++ language have no meaning. In C++, space characters are not compiled. Therefore , you can use as many spaces as you want. In general,a lot of space characters are used to make the program read better.

init main() {cout<<"Hello Utopian";  return  0; }

The above program writes "Hello Utopian" to the screen. returns '0' to the operating system and waits. Because all commands are written side by side and without spaces , it is a bit difficult to read. If we write the above program using empty and subline,it will be read more easily as shown below.

int main ( )
{
          cout<<"Hello Utopian";
          return 0;
}

If careful, the code in the above program is distributed to different lines and the commands inside the block are written in , the readability is increased. If you use 'dev-C++' as the editor,it will try to handle the regular use of spaces itself.

Capitalization and lowercase usage

The C ++ language is a case-sensitive language. So, for the C ++ language, "Utopian" and "Utopian" are different things.

int x=1;
int y=2;
init total=0;
TOTAL=x+y;
cout<<TOTAL;

n the above program, three variables named x, y and total are defined. In the following lines, "TOTAL" is written instead of "total". You will get an error because "total" and "TOTAL" are different things.

For example, if you type 'cout <<' incorrectly as 'Cout <<', you will get an error. To avoid such mistakes, I recommend you to write careful code as much as possible. Some editors have an automatic code completion feature called 'Intellisense'. This feature ensures that both commands are completed and written correctly.

** Variables:**

Variables are memories used to temporarily store values ​​generated from the outside or generated in the program.
Variable according to the size and type of the data to be stored must be different boutta and type. In the table below you can see some data and types that can be read from the outside.

Read ValueVariable DataType
5left-aligned
235000:255 small integer between ( unsigned char)
-1250000:65535 integer between ( unsigned short)
-125000-2billion:+2billion between (int)
3,14Decimal Number ( float)
'a'Character ( char )
"Hello Utopian"Text ( String )

The most important thing to pay attention to is the compatibility of the external variable with the value to be assigned:

  • If you are getting an integer such as 5 from outside, the variable to which this integer is assigned must be of type integer (short int, int).
  • If you are getting a decimal number from outside, such as 3.14, the variable to be used must be decimal (float, double).
  • If you are importing text from outside, such as 'z' or 'Hello Utopian', the variable to be assigned must be of the verb (char) type.
    If you can not assign the data to the variables of the appropriate type, you will get an error at compilation. This error tells you that the data and the variable are not the proper type.
    In the long run, when assigning a variable value, make sure that the data on both sides of the assignment is of the same type. If it is not the same, you need to convert it to the appropriate data type. We will later learn how data types are translated.
variable ( same data type ) =  value ( same data type );

**Variable Physical Structure: **

In short, I would like to talk a little bit about the physical structure of the variables. The variables, RAM, are stored in shelf-like areas in memory. The memory that stores 8 0's or 1's memories creates one and 1 Bytes of memory together. In the RAM memory, 1 byte of memories are arranged like sub-sub racks.

Some information:

  • A bit (bool) value can be either 0 or 1
  • If all the bits in a line (BYTE) are 0, the decimal value is 0. If all the bits in a line are 1, the decimal value is 255.
  • 00000000=> 0
  • 11111111=>255
  • If the 16 bits (lower byte 2 bytes) are all 0, the decimal counter is 0. If all goes 1, it will be 65,535
  • 00000000 00000000=>0
  • 11111111 11111111=>65.535
  • If all 32 bits (lower byte 4 bytes) are 0, the decimal counter is 0. If all goes 1, it's 4.294.967.295 (four billion).
  • 00000000 00000000 0000000 00000000 =>0
  • 11111111 11111111 1111111 11111111=> 4.294.967.295
  • Each character (char) such as A, b, @ occupies 1 byte in RAM memory. So, "Utopian" occupies 7 BYTE space in RAM memory.

The ram memory structure is especially important for variables and data types. The different types of data stored in the memory are different amounts of space. Here are some examples:

  • Mr / Mrs information will be saved as 0/1, but each record occupies 1 bit in RAM memory.
  • Married / Single information will be saved as 0/1, but each record occupies 1 bit in RAM memory.
  • Values ​​from 0 to 255 occupy 1 bit in RAM memory, ie 8 bits; For example, if a student enters a note between 0 and 100, each note takes up 1 byte of RAM memory.
  • Values ​​from 0 to 65,535 occupy 2 bytes in RAM memory, ie 16 bits. For example, to save the load weight from 0 to 5.000 KG, it is necessary to allocate 2 bytes in the RAM memory.
  • Values ​​between 0 and 4 Billion occupy 4 bytes, or 32 bits, in RAM memory. For example, to save the knowledge of a company whose size varies from 1 to 4 billion, you need to allocate 4 BYTE (32 bits) in RAM memory.



Series :

1 - C++ Programming Languages With / Series 1 #1



Posted on Utopian.io - Rewarding Open Source Contributors

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center