https://github.com/avinandanbose/c_plus_plus_beginner
Its the beginner series of C++
https://github.com/avinandanbose/c_plus_plus_beginner
beginner beginner-code beginner-friendly cplusplus cplusplus-11 cplusplus-14 cplusplus-17 cplusplus-20 cpp cpp11 cpp14 cpp17 cpp20 tutorial tutorial-code tutorial-exercises tutorials tutorials-explained tutoring
Last synced: 2 months ago
JSON representation
Its the beginner series of C++
- Host: GitHub
- URL: https://github.com/avinandanbose/c_plus_plus_beginner
- Owner: AvinandanBose
- License: mit
- Created: 2022-06-07T06:56:37.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-31T18:44:47.000Z (over 2 years ago)
- Last Synced: 2024-12-25T22:24:03.711Z (4 months ago)
- Topics: beginner, beginner-code, beginner-friendly, cplusplus, cplusplus-11, cplusplus-14, cplusplus-17, cplusplus-20, cpp, cpp11, cpp14, cpp17, cpp20, tutorial, tutorial-code, tutorial-exercises, tutorials, tutorials-explained, tutoring
- Language: C++
- Homepage:
- Size: 297 KB
- Stars: 7
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# C-plus-plus-Beginner-
Its the beginner series of C++Program - Hello World
Streams IO
Data Types
Constant Qualifiers:→ENUM , CONST, DEFINE
GLOBAL AND LOCAL VARIABLE
Display Message
Scope Resolution Operator
Registry Keyword
Operators in C++
- Arithmetic Operator
- Relational Operator
- Assignment Operator
- Increment and Decrement Operator
- Increment and Decrement Operator
- ConditionalOperator
- BitWise And Operator
- Bitwise OR Operator
- Bitwise XOR Operator
- Bitwise Left Shift Operator
- Bitwise Right Shift Operator
- Bitwise NOT Operator
BitWise Operators
Special Operators
Type Conversion/Type Casting
Type conversion (or typecasting) means transfer of data from one data type to another.There are two type of conversion :
1) Implicit Conversion : Here compiler automatically assigns data types and helps in conversion . Suppose we have float value 10.3 and we convert to integer then we get 10 and 0.3 is truncated or process is known as Truncation. Now suppose we have a integer value say 5 and we converted to a float by multiplying it with 10.5 we get 50.5 , such conversion of lower data type(lower range of values or has lower precession) to a higher type (higher range of values or has higher precession) is known as promotion and similarly if we convert it to integer i.e. lower data type again is called as demotion.
2) Explicit Conversion : Here compiler put data type explicity before another while runtime help in data type conversion.
```Syntax
(data_type) expression/variable name
`````
TypeDef Statement
More on Constants
Branching Statements
Branching statements alter sequential execution of program statements. Following are the branching statements supported by C++
a. Decision Making Statement : Decision making statements allow you to decide the order of execution of specific statements in our program. It is done by setting up a condition and when the decided condition is met , desired statements gets executed.
b. Jump Statement :(explained below)
Looping Statements/ Iteration Statements
Loops cause a section of code to be executed repeatedly until a termination condition is met. The following are the looping statements supported in C++
a. Entry Controlled Loop : Checks Condition At Entry Level
b. Exit Controlled Loop : Checks Condition At Exit Level
Jump Statements
Jump statements cause an unconditional jump to another statement elsewhere in the code supported in C++
* Go-To Statement is a Branching Statement is one of the Jump Statement, already done*
Selection Statements
Selection statements allow a program to test several conditions, and execute instructions based on which condition is true.
Fixed Width Integer Types (since C++11)
Includes the Standard C library header and adds the associated names to the std namespace. Including this header ensures that the names declared using external linkage in the Standard C library header are declared in the std namespace.
Functions(CALL BY VALUE)
There are two types of Functions: 1) Library functions , which are contained in C++ library and we use it in our program by default and 2) User Defined Functions : The functions that are created by users for some specific functionality , here is all about user defined functions.
- →Function Declaration provides the name of the function to the compiler
- →Function Declaration provides the type(Return Data Type) of value to be returned to the compiler
- →Function Declaration provides the type of argument to be passed to the compiler
- →Function Declaration provides all such information to the compiler before execution of the program
- →Function Declaration ends with semicolon and have no body.
```Syntax
return_data_type function_name(data_type for formal_argument1,data_type for formal_argument2,.....);
`````
Function Definition, where actual function is elaborated in details , it have body and doesnot end with semicolon.
```Syntax
return_data_type function_name(formal parameter/argument lists){
//function body
}
`````
- →Formal Arguments are passed in Function Definition
- →Formal Arguments are also known as Dummy Parameters or Placeholders
- →Formal Arguments are basically used to show how the function works.
- →Formal Arguments are called Dummy or Placeholders as they carry Actual Parameters's values or directly with values assigned during Function Call. They are created during starting of a function and gets destroyed after the execution of the function is over just similar to local variables.
- →Actual Parameters/Arguments are mentioned during function call
- →Actual Parameters/Arguments and Formal Parameters/Arguments holds seperate memory locations, hence the value of the actual parameter cannot be modified by formal parameter or formal parameter gets replaced by actual parameter. The value of the actual parameter is copied to formal parameter for further execution
Function Call:,A function is a dormant entity which comes to life , when a call is made to the fucntion, It contains: Function name followed by either actual parameters or values for the formal parameters enclosed within parentheses(), terminated by a semicolon(;).
```Syntax
function_name(actual arguments/values for formal arguments);
`````
Passing Arguments By Value:,When a value is passed as arguments i.e. either value assigned to actual arguments or directly values are passed at place of arguments further gets processed by formal arguments / parameters during execution of a function.
Call By Value:That is Function Call by Value which means when a function is called passing values as arguments.
Examples on Functions:
- Example 1:Count Number of Digits using Function
- Example 2:Reverse of a number using Function
- Example 3:Palindromic Number Upto A Given Range using Function
- Example 4:Prime Numbers through Function
- Example 5:Prime Numbers upto a Range through Function
- Example 6:Factorial of a number using Function
- Example 7:Factorial Numbers Upto A Given Range using Function
- Example 8:Twin Prime Numbers Upto A Given Range using Function
- Example 9:Buzz Numbers Upto A Given Range using Function
- Example 10:XOR SWAPPING using Function
Inline Function
During Normal execution of function , compiler copies necessary values to memory registers like a stack (Overhead) and goes back to function call , this jumping to and from the calling statement cause overheads which can expand the execution time. Hence in such cases we can use inline function . Which can be done with the inline keyword.
```Syntax
inline return_data_type function_name(formal parameter/argument lists){
//function body
}
`````
Note: Though we use inline keyword , C++ compiler decides which functions need to be inline , moreover we basically use "inline" keyword to small function type noting such function might not produce maximum overheads expanding the execution time.
Example on InLine Function:
MACRO FUNCTION
There are numerous short function which we achieve using #define macros like Inline .
```Syntax
#define function_name(parameters) (function body)
`````
Example on MACRO FUNCTIONS:
Drawbacks of Macro type functions : if it is defined as #define add(x, y) x + y and called as 4*add(a, b) where a = 10 and b = 20 , then it will first do multiplication of 4*10 = 40 then add with 20 to make the output 60 i.e. expanding order which is not a normal function does . To get accurate result , of what a function actually would perform what we have to do is just : #define add(x, y) (x + y) which will prioritize the x+y first . Hence this differentiate between a Macro type function and others functions such as an inline one. Moreover Macro type function doesnot check the type check of the variable i.e. here the type of x and y.
Example on MACRO FUNCTIONS which differentiate between a normal function:
Recursive Functions
When a function call itself until it reaches its base condition for termination , such type of functions are known as Recursive Functions and call to such functions are called recursive calls. They allow for more efficient way of code writing.
A. DIRECT RECURSIVE FUNCTION: If a function calls itself, it's known as direct recursion. This results in a one-step recursive call: the function makes a recursive call inside its own function body.
Example on DIRECT RECURSIVE FUNCTIONS:
- Example 1 :Print Number from 1 to Range
- Example 2:Sum of Numbers
- Example 3:Sum of Digits
- Example 4:Count of Digits
- Example 5:Factorial of a number
- Example 6:Fibonacci Series
- Example 7:Calculation of Power
- Example 8:Prime Number upto a Range
B. INDIRECT RECURSIVE FUNCTION: If the function f1 calls another function f2 and f2 calls f1 then it is indirect recursion (or mutual recursion).
This is a two-step recursive call: the function calls another function to make a recursive call.
Example on INDIRECT RECURSIVE FUNCTIONS:
- Example 1 :INDIRECT RECURSIVE FUNCTION-1
- Example 2 :INDIRECT RECURSIVE FUNCTION-2
- Example 3 :INDIRECT RECURSIVE FUNCTION-3
INDENTATION IN C++
It makes code easier to read . It changes style and gives us better understanding of syntax. Such as we remove braces {} in single bodied if , if-else , for and while loops.
Example on INDENTATION:
- Example 1 :Single If Identation
- Example 2 :If-Else Indentation
- Example 3 :For-Loop Identation
- Example 4 :While-Loop Identation
Scope Resolution Operator :: on Indentation
Scope Resolution Operator just works similar as above removing braces {} in single bodied if , if-else , for and while loops.
Example on Scope Resolution Operator :: on Indentation:
- Example 1 :Single If Identation With Scope Resolution Operator
- Example 2 :If-Else Indentation With Scope Resolution Operator
- Example 3 :For-Loop Identation With Scope Resolution Operator
- Example 4 :While-Loop Identation With Scope Resolution Operator
More Examples
- Example 1:Length of Digits
- Example 2:Armstrong Number
- Example 3:Armstrong Number upto a range
- Example 4:Reverse of a number
- Example 5:Factorial of a number
- Example 6:Strong Number or Krishnamurthy Number Number
- Example 7:Strong Number or Krishnamurthy Number upto a Range
- Example 8:Sum of all digits upto a given range
- Example 9:Perfect Number
- Example 10:Perfect Number upto a given range
- Example 11:Fibonacci Series upto a given range
- Example 12:Highest Common Factor/Greatest Common Divisor
- Example 13:Least Common Factor/ Least Common Multiple
- Example 14:Automorphic Number
- Example 15:Automorphic Number upto a given Range
- Example 16:Prime Number using Flag(1)
- Example 17:Prime Number using Flag upto a given Range(1)(1)
- Example 18:Prime Number using Flag Type 2
- Example 19:Prime Number using Flag Type 2(2)upto a given range
- Example 20:Prime Number using Boolean Flag Type upto a given range
- Example 21:Prime Number using Boolean Flag Type upto a given range(1)
- Example 22:Composite Numbers upto a range -1
- Example 23:Composite Numbers upto a range -2
- Example 24:Composite Numbers upto a range -3
- Example 25:Composite Numbers upto a range -4
- Example 26:Palindromic Number
- Example 27:Palindromic Number upto a given Range
- Example 28:Twin Prime
- Example 29:Non Fibonacci Numbers Upto A Given Range
- Example 30:Prime Fibonacci Numbers Upto A Given Range
- Example 31:Palindromic Prime(PAL PRIME)
- Example 32:Palindromic Prime(PAL PRIME) upto A Given Range
- Example 33:Decimal To Binary(For a single decimal digit input)
- Example 34:Decimal To Binary For a given Range
- Example 35:Decimal To Octal(For a single decimal digit input)
- Example 36:Decimal To Octal(Upto a Given Range)
- Example 37:Binary To Decimal
- Example 38:Octal To Decimal
- Example 39:Buzz Number
- Example 40:Buzz Number Upto A Given Range
- Example 41:Duck Number
- Example 42:Duck Number Upto A Range
- Example 43:Neon Number
- Example 44:Neon Number Upto A Given Range
- Example 45:Sum Of Digits of a number
- Example 46:Even Number Upto A Given Range
- Example 47:ODD Number Upto A Given Range
- Example 48:Swapping Using Third Variable
- Example 49:Swapping Without Using Third Variable(Using Addition and Subtraction)
- Example 50:Swapping Without Using Third Variable(Using Multiplication and Division)
- Example 51:Swapping Using XOR Operation
Scope Resolution Operator just works similar as above removing braces {} in single bodied if , if-else , for and while loops.
Example on Scope Resolution Operator :: on Indentation:
- Example 1 :Single If Identation With Scope Resolution Operator
- Example 2 :If-Else Indentation With Scope Resolution Operator
- Example 3 :For-Loop Identation With Scope Resolution Operator
- Example 4 :While-Loop Identation With Scope Resolution Operator
More Examples
- Example 1:Length of Digits
- Example 2:Armstrong Number
- Example 3:Armstrong Number upto a range
- Example 4:Reverse of a number
- Example 5:Factorial of a number
- Example 6:Strong Number or Krishnamurthy Number Number
- Example 7:Strong Number or Krishnamurthy Number upto a Range
- Example 8:Sum of all digits upto a given range
- Example 9:Perfect Number
- Example 10:Perfect Number upto a given range
- Example 11:Fibonacci Series upto a given range
- Example 12:Highest Common Factor/Greatest Common Divisor
- Example 13:Least Common Factor/ Least Common Multiple
- Example 14:Automorphic Number
- Example 15:Automorphic Number upto a given Range
- Example 16:Prime Number using Flag(1)
- Example 17:Prime Number using Flag upto a given Range(1)(1)
- Example 18:Prime Number using Flag Type 2
- Example 19:Prime Number using Flag Type 2(2)upto a given range
- Example 20:Prime Number using Boolean Flag Type upto a given range
- Example 21:Prime Number using Boolean Flag Type upto a given range(1)
- Example 22:Composite Numbers upto a range -1
- Example 23:Composite Numbers upto a range -2
- Example 24:Composite Numbers upto a range -3
- Example 25:Composite Numbers upto a range -4
- Example 26:Palindromic Number
- Example 27:Palindromic Number upto a given Range
- Example 28:Twin Prime
- Example 29:Non Fibonacci Numbers Upto A Given Range
- Example 30:Prime Fibonacci Numbers Upto A Given Range
- Example 31:Palindromic Prime(PAL PRIME)
- Example 32:Palindromic Prime(PAL PRIME) upto A Given Range
- Example 33:Decimal To Binary(For a single decimal digit input)
- Example 34:Decimal To Binary For a given Range
- Example 35:Decimal To Octal(For a single decimal digit input)
- Example 36:Decimal To Octal(Upto a Given Range)
- Example 37:Binary To Decimal
- Example 38:Octal To Decimal
- Example 39:Buzz Number
- Example 40:Buzz Number Upto A Given Range
- Example 41:Duck Number
- Example 42:Duck Number Upto A Range
- Example 43:Neon Number
- Example 44:Neon Number Upto A Given Range
- Example 45:Sum Of Digits of a number
- Example 46:Even Number Upto A Given Range
- Example 47:ODD Number Upto A Given Range
- Example 48:Swapping Using Third Variable
- Example 49:Swapping Without Using Third Variable(Using Addition and Subtraction)
- Example 50:Swapping Without Using Third Variable(Using Multiplication and Division)
- Example 51:Swapping Using XOR Operation