Its the beginner series of 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
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.
(data_type) expression/variable name
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.
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++
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 allow a program to test several conditions, and execute instructions based on which condition is true.
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.
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.
return_data_type function_name(data_type for formal_argument1,data_type for formal_argument2,.....);
return_data_type function_name(formal parameter/argument lists){
//function body
}
- β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 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_name(actual arguments/values for formal arguments);
- 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
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.
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.
#define function_name(parameters) (function body)
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.
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 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 1 :INDIRECT RECURSIVE FUNCTION-1
- Example 2 :INDIRECT RECURSIVE FUNCTION-2
- Example 3 :INDIRECT RECURSIVE FUNCTION-3
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 1 :Single If Identation
- Example 2 :If-Else Indentation
- Example 3 :For-Loop Identation
- Example 4 :While-Loop Identation
Scope Resolution Operator just works similar as above removing braces {} in single bodied if , if-else , for and while loops.
- 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
- 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