C++_Notes_Day-1
C++_Notes_Day-1
Toolchain: gcc
Install MingW Gcc/G++
Setup path of bin folder to env
IDE: Eclipse
Install CDT extention from eclipse marketplace
Change perspective to C/C++
Introduction to C/C++
C brief history
Founder of C: Denis Riche
Year: 1972
Bell Lab
Hardware: PDP-11
C/C++ are the statically type checked as well as strongly types checked programming language
C is known as general purpose programming language
a=900; //OK
a="Malkeet"; //OK
int a; //a is variable of type integer having 2 bytes memory and storing GV as
value and range of this variable can be min (-32678) to max (32677)
//Action:1. Reserve 2 bytes memory, labled that memory with 'a' and put GV as
value
Syntax-2
Syntax-3
Syntax-4
Syntax-5
int main(void)
{
return 0;
}
Syntax-6
void main(void)
{
Syntax-7
void main()
{
Reference: https://en.cppreference.com/w/c
Software Development Kit: Development Tools + Documentation + Runtime Environment + Supporting
Libraries
Development Tools:
Editor: It is used to create/edit the source file (.c/.cpp)
Example:
Windows: Notepad, Notepad++, Visual Code, Wordpad etc.
Linux: nano. vim, vi, gedit, VS Code etc.
Mac OS: Vim, vi, TextEditor, VS Code etc.
Preprocessor
It is a system program whose primary job is to:
To remove comments from the source file.
To expand macros.
Example: CPP (C/C++ Preprocessor)
Preprocessor generates intermediate file (.i/.ii)
Compiler
It is a system program whose primary job is to:
To check Syntax.
To convert a HLL code into low-level language code (Assebmly Language / Code)
Example:
Turbo C: tcc.exe
MS Visual Studio: cl.exe
Linux: gcc
Compiler generates .asm/.s file.
Assembler
It is a system program which is used to convert low-level language code into machine
level language.
Example:
Turbo: Tasm
MS Visual Studio: Masm
Linux: as
Assembler generates .obj/.o file.
Linker:
It is system program whose job is to link machine code with Supporting Libraries files.
It is responsible for generating executed file (.exe).
Example:
Turbo: Tlink.exe
MS Visual Studio: link.exe
Linux: ld
Loader:
It is an OS API.
It is used to load executable file from HDD to Main memory (RAM).
Debugger:
Logical error inside a program is known as bug.
To identify the bugs we need Debugger.
Example: gdb,ddd
Documentation
It can be in the form .html/.pdf/.txt format.
Example: https://www.tenouk.com/ModuleW.html
Runtime Environment
It is responsible for the entire execution of program / application.
Example: C Runtime
C Flow of execution Image
Reference : https://www.tenouk.com/ModuleW.html
Comments: Comments inside the program are used to maintain Documentations
Single Line Comments: //Double Forward slash is used to put single line comments
Multiline Comments / Block Comments: /* */ is used to put block comment
/*
Multiline or Block Comments
*/
int main()
{
void Add(); //Function Declaration (Local Declaration of Add Function)
cout<<"Am Main"<<endl;
Add(); //Function Call
return 0;
}
void Add() //Function Definition
{
cout<<"Am Add";
}
Global Function Declaration
cout<<"Am Main"<<endl;
Add(); //Function Call
return 0;
}
void Add() //Function Definition
{
cout<<"Am Add";
}
void Add()
{
cout<<"Am Add";
}
int main()
{
Add();
cout<<"Am Main"<<endl;
return 0;
}
Linker Error:
If we call a function without giving its definition
#include<iostream>
using namespace std;
void Add();
int main()
{
Add(); //If you call a method without giving its definition then linker will
generate error
cout<<"Am Main"<<endl;
return 0;
}