Basics of C++ for Beginners | Learn C++ Programming

Before diving into introduction to c++ language, first you have to know why do we need to learn this language?

Basically, it's a language that allows a user to communicate with a computer.Just like human uses various languages to communicate e.g., English, Spanish, French etc., Computers understands only machine language which is in the form of "0" and "1" but that is low level language or object code that is not far from human language so we use compilers in order to convert our source code into object code. Some compilers like turbo c++, code block etc.!




Introduction:

C++ is a high level language that supports procedural as well as object-oriented model. It is an extension of c language by Dennis Ritchie at bell labs.

Its main objective was to write operating system and utilities for Unix operating system.

Compiler:

Source code is in high-level language compiler takes the source code from the user and convert sources code into object code with .obj extension that is understandable by computer directly.It cannot compile source code is it has syntax errors, it will generate a syntax error and the line where the error is located.




Basic format:

#include<iostream>

using namespace std;

int main()

{

.......

return 0;

}

1. Here in this first line also known as preprocessor directives which is used to include header files from the library for various functions (there are many header files in the library, but each has its own function). The iostream header file basically stores a cout and ci an object which is used to input and display the data to and from user and console.

2. In second line we have used standard that lines prevent us not to write std:: before every statement.


3.” int main” is the main function and uses curly braces, allowing the user to write the body of the program.


4. We have return 0 as main function type was "int" it will further clarify when we will learn about user defined functions.

⇒Some terms that you should be familiar with:

Keywords:

There are some keywords used in c++.  They are reserved for some special purpose and has predefined meanings.They are integral part of language syntax and can't be used as variable or function names.



Examples of keywords:


1. auto

2. bool

3. break

4. case

5. char

6. class

7. const

8. continue

9. default

10. do

11. double

12. else

13. explicit

14. extern

15. false

16. float

17. for

18. goto

19. if

20. int

21. long

22. mutable

23. private

24. protected

25. public


Variables:

Variable as name indicates it is the name whose value can be changed. It occupies the space in memory according to its data type.

Syntax:

Data_type variable_name;

Rules:

1. Variables should not be a key word.

2. Variables should not use spaces between them.

3.variables can't start with number or special symbols etc, it can only begin with underscore and alphabet.

4. Use semicolon at last.

Constants:

For Constants quantity we can't change its value as its value is same throughout the program.

Syntax:

Const data_type constant_name;

Data types:

The type or nature of the quantity is declared or initialize is called data type

There are few types of data types:

1. int for integers

2. float for decimal values

3. double for long float values

4.long for larger quantity 

Declaration:

Declaration in c++ means to declare a variable with its data type

E.g. 

int a;

float b;

Initialization:

In initialization, we assign a value to a variable with its data type.

E.g.

int a=10;

Functions:

If we want to apply the same operation multiple times in a program, we go for functions that are convenient because we don't have to write every time same statements for the same operation.It is a reusable facility that allows the user to use wherever it is required.

Arrays:

Suppose we have to enter marks of 100 students and variable is marks, so are we going to write 100 variables?

Obviously not, here we will use arrays which can store all the marks of 100 students without declaring 100 variables.It is also known as continuous data structure that allows us to search, insert, delete, transversal of data with same data type.

We use square brackets for arrays:

E.g.

int arr[ ];

=⇒Steps of execution of c++ program

1.write a program in compiler that allows to write, edit, delete the program statements.

2.compile by pressing 

Ctrl + Shift + B. The program will not compile if it has some syntax errors. It save the file with .obj extension.

3.link the library file using linker

4.run object code ny pressing 

Ctrl + F5.

5.file is saved with .exe extension.

=⇒C++ selection structure:

C++ allows us to select between various choices and print whatever we want according to given conditions

For this purpose, we use selection statements:

1. If statement.

2.if-else statements

3.if-else-if statements

4.switch statements

=⇒Repetitive structure:

We can print multiple statements without writing all over again and again by using loops

1.for loop

2.while loop

3.do while loop



Summary of Introduction to C++ Language:


— Learning Objectives C++:

 —C++ allows users to interact with computers, similar to how humans use languages ​​such as English or Spanish.

 —Computers understand machine language, represented by "0" and "1", but C++ allows users to write code in a human-readable format.


- Introduction to C++: .

  - C++ is a high-level language that supports programming and object related modeling.

  - Is an extension of the C language, developed by Dennis Ritchie at Bell Labs.

  - Originally designed to write programs and utilities for the Unix operating system.

- Compiler: .

  - Convert high-quality source code into machine-readable object code.

  - Check for syntax errors in the source code during compilation.


- Original Configuration: .

  - Preprocessor directives like `#include<iostream>` are added to header files.

  - Use `name space std;` to avoid typing `std::` before each argument.

  - `int main()` as the main function where the program execution starts.

  - `return 0;` to indicate successful completion of the main operation.


- Conditions to Know:

  - Keywords: Reserved words with default meanings that are important in language syntax.

  - Variable: named storage locations whose values ​​can change.

  - Constants: Parameters with fixed values ​​throughout the program.

  - Data Types: Types of data stored in a variable.

  - Functions: Reusable pieces of code that perform a specific function.

  - Arrays: Data structures that allow multiple objects of the same data type to be stored.

- Steps for a C++ program:

  1. Write and edit the program in the compiler.

  2. Compile the function and check for syntax errors and save with an .obj extension.

  3. Merge the library files with lin.

Comments

Post a Comment

Popular posts from this blog

Bitcoin Price Prediction In 2024: Boom Or Bust?

How to hack Facebook account using termux (password guessing method)

From Start To Success| A Step By Step Guide To Becoming A Profitable Amazon Seller