Skip to content

AvinandanBose/C_PLUS_PLUS_Beginner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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++



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.

(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 always starts with function declaration in C/C++
    • β†’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.
    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.
  • return_data_type function_name(formal parameter/argument lists){
    //function body
    }

  • There are two types of Argument/Parameters are maintained in Functions: 1)Formal Argument/Parameter , 2) Actual Argument/Parameter
    • β†’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(;).
  •  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:

    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.

    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 .

    #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:

    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:

    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:

    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:

    More Examples

    Patterns:(Uploading.....)