C++ Tutorial For Beginners: Module 1 | Learn C++ in 1 Hour | C++ Basics | Data Structures | @SCALER

Estimated read time: 1:20

    Summary

    In this engaging C++ tutorial for beginners, Anul Sadaria from Google starts with a basic introduction to programming and its real-world applications. The tutorial quickly moves into the nuances of C++, a language favored for its speed and hardware proximity. Key concepts like programming languages and their particular strengths, such as Python for data analysis and JavaScript for web development, are explained. Anul dives into the advantages of C++, including its efficiency, flexibility in memory management, and its object-oriented nature, before guiding the audience through writing their first C++ program and understanding its structure, from headers to main functions. The tutorial concludes with an exploration of basic data types, variables, operators, and conditional statements, setting the stage for more advanced topics in upcoming modules.

      Highlights

      • Anul introduces the fundamental concept of programming as giving instructions to a machine. 🤖
      • He explains programming languages like C++, Python, Java, and their diverse applications. 🌐
      • The session covers the birth and benefits of C++, emphasizing its efficiency and object-oriented nature. 🏎️
      • Viewers code a 'Hello World' program exemplifying C++'s structure and compilation process. 💻
      • Topics like data types, operators, and control structures pave the way for advanced learning. 🚀

      Key Takeaways

      • Discover the basics of C++ programming and dive into real-world applications. 📚
      • Anul Sadaria provides a hands-on guide for beginners to start programming in C++. 🖥️
      • C++ is highlighted for its performance efficiency and proximity to hardware. 🔥
      • Learn to write and compile your first C++ program and grasp its key structures. ✍️
      • Understand the significance of data types, variables, and conditional statements in C++. 💡

      Overview

      Anul Sadaria, a software engineer at Google, provides a comprehensive introduction to C++ programming, starting with what programming is and transitioning into how C++ fits within the ecosystem of programming languages. He highlights the efficiency of C++, its ability to handle memory management, and its proximity to hardware, which makes it distinct from other languages like Python and Java.

        The tutorial walks viewers through setting up a C++ environment, writing a basic 'Hello World' program, and understanding how to compile it. Anul explains the importance of programming structures such as headers and main functions while discussing the workflow from writing code to execution. This foundational knowledge prepares users to tackle more sophisticated aspects of C++ programming.

          In wrapping up, Anul covers integral C++ concepts such as data types, variable declaration, and operators, emphasizing conditional statements and decision-making which are crucial for programming logic. This module sets the stage for more challenging topics like loops, functions, and data structures, promising a deeper dive in upcoming sessions.

            Chapters

            • 00:00 - 03:00: Introduction Anul Sadaria, a software engineer at Google, introduces the video as a starting point for learning C++ from scratch. The chapter will cover the fundamentals of programming, real-life applications, and the basics of C++. Additionally, viewers are encouraged to explore free master classes offered by Scaler on their event page.
            • 03:00 - 06:00: Understanding Programming This chapter begins with an introduction to the concept of programming, framed both in simple terms and a more technical definition. Programming is described as a set of instructions executed by a machine. The chapter aims to clarify this concept with relatable analogies, starting with a real-life example involving the speaker's mother.
            • 06:00 - 10:00: Programming Languages Overview The chapter 'Programming Languages Overview' uses an analogy to explain how programming languages provide a set of instructions that machines are expected to follow with accuracy. Unlike humans, who may not execute instructions perfectly and with 100% accuracy, machines are expected to perform tasks as instructed without independent thought. The chapter does not delve into artificial intelligence, focusing instead on the precision expected from machines when executing coded instructions.
            • 10:00 - 19:00: C++ and its Benefits This chapter explains that a program is essentially a set of instructions that make up a code, and the skill of writing such a program is called programming. Importantly, it highlights that programming is not limited to computers alone. It extends to various automated systems, including flight and car automation, indicating the ubiquitous nature of programs in modern technology.
            • 19:00 - 28:00: Hello World and Compilation Process This chapter discusses the integration of programming in various technologies, using the example of cricket and the Decision Review System (DRS). It explains how technical systems like Sneaker and Hawkeye are driven by programs, highlighting the importance of programming in modern technological solutions.
            • 28:00 - 36:00: Data Types This chapter begins by using the metaphor of the evolution of Formula 1 racing to illustrate how technology and programming have permeated various aspects of life. It talks about sensors in Formula 1 cars and tracks, collecting significant data that is then analyzed to enhance the sport. The broader message is about the ubiquitous integration of programming and data analysis in different fields and the prediction that this trend will continue, encapsulating different facets of the world in the future, emphasizing the growing significance of data types in this digital evolution.
            • 36:00 - 44:00: Variables and Memory The chapter begins by connecting the significance of programming and its real-world applications to everyday language. The main focus is on programming languages, which are likened to human languages like Hindi, English, and other regional languages. The idea is that just as people use different languages to communicate the same message, programmers use different programming languages to instruct computers to perform tasks. This sets the foundation for understanding how language translates into computational instructions.
            • 44:00 - 47:00: Input and Output in C++ The chapter explores the concept of Input and Output operations in the C++ programming language. It provides an understanding of how C++ handles input and output functionalities, differentiating it from other programming languages. The chapter also gives a brief overview of different programming languages, mentioning that there are hundreds of them, with some becoming obsolete and others becoming popular due to their specific use cases. Additionally, it acknowledges that languages like Python, Java, JavaScript, besides C++, cater to different programming needs.
            • 47:00 - 65:00: Operators in C++ The chapter focuses on C++ operators and their versatility in programming. It highlights how C++ operators are applicable in various domains such as data handling, machine learning, deep learning, and artificial intelligence. Additionally, it contrasts the use of Python, noting its frameworks beneficial for data analytics, and mentions the widespread influence of JavaScript in web development, both on the client and server sides.
            • 65:00 - 83:00: Decision Making in C++ The chapter discusses the use of different programming languages in software development, focusing on client-side and server-side languages. It explains that JavaScript is predominantly used on the client-side, while Java and C++ are typically utilized for server-side development. Additionally, the text mentions that Java can also be used for app development, either through Java native or Kotlin, which is built on top of Java.
            • 83:00 - 96:00: Switch Statements The chapter "Switch Statements" discusses the benefits of using the C++ programming language in various applications, including mobile development and web servers. C++ is highlighted for its speed, closeness to the hardware, and performance efficiency compared to other languages such as Python. The content indicates a focus on C++, describing it as a favored language, supported by references to a podcast for further exploration of its advantages.
            • 96:00 - 101:00: Conclusion and Next Steps The conclusion chapter reiterates the focus of the module on C++, emphasizing its performance efficiency and utility as a server-side language. The chapter briefly mentions the importance of understanding the origins and necessity of C++ at the time of its creation, setting the stage for a deeper exploration into the language's significance.

            C++ Tutorial For Beginners: Module 1 | Learn C++ in 1 Hour | C++ Basics | Data Structures | @SCALER Transcription

            • 00:00 - 00:30 hey everyone this is anul sadaria software engineer at Google in this video we will start from scratch with C++ we will talk a little bit about what programming is and what are the real life applications of programming and then we will jump directly into the basics of C++ but before we do that don't forget to check out scalers free master classes taken by industry-leading experts only on scalers event page link
            • 00:30 - 01:00 is in the description below now let's get started so now let's begin with a very fundamental question what is programming okay programming is to put it into very lame and words and as well as like keeping a cliche technical definition program is a set of instructions okay set of instructions which are executed by a machine now if I want to compare it with a real life analogy for example whenever my mother goes out of
            • 01:00 - 01:30 town what she does is She lays out a set of instructions that when you wake up take milk from outside boil it put it in the refrigerator wake up your sibling and so on like there are a set of instructions provided to me which I need to fulfill obviously being human beings we don't execute them to the Perfection and with 100% accuracy but we expect the machines to be 100% accurate and not think on their own obviously I'm not going into the artificial intelligence side of it but machines are expected to follow whatever instruction instu we
            • 01:30 - 02:00 give to them so these set of instructions is what makes up a program or a code okay so that is what program is and the Art of writing a program is what programming is now it's important to understand that programming is not just restricted to the computers okay you like you you might be taking flights or you might be going by cars so programs exist there as well like wherever you go whatever part is automated there a program is existing
            • 02:00 - 02:30 for example let's say you are a cricket fan okay now you are watching World Cup okay now whenever a player takes a DRS okay uh decision review system so whenever a DRS is taken so there is a sneeter there is Hawkeye and all those different angles of cameras are there and then a decision is taken so programming exist in all those things like sneaker is a technical thing where a program is driving that particular piece of software okay Hotpot used to be
            • 02:30 - 03:00 there once upon a time so in that also there used to be some sort of a program underlying now if you are a Formula 1 fan you would have known how the sport has evolved over a period of time there are tons of sensors everywhere on the Formula 1 track in the Formula One cars as well all the data is collected and then analytics are done on top of it so programming is going to encapsulate the entire world at some moment in future it has already started to spread everywhere and anywhere so those are like just to
            • 03:00 - 03:30 give you a little detail like that is what programming means and those are the real life applications of programming you know so now moving on to the main part I don't want to bore you with a lot of theoretical stuff now what are programming languages so you can use different types of for example like someone speaks in Hindi someone in English and someone uses their own like different Regional languages they want to try and communicate the same thing in their own language so similarly programming languages all the
            • 03:30 - 04:00 programming languages are meant for a program execution but they can be written in different languages for example there are languages like C++ is there java is there python is there JavaScript is there and just to give you a fair idea there are obviously more than hundreds of programming languages at this stage some of them have become obsolete some of them are trending nowadays some of them are meant for a particular use case itself now to talk about python like python is a very
            • 04:00 - 04:30 versatile language you would have seen its application with anything related to data machine learning is there deep learning is there artificial intelligence python provides a lot of Frameworks related to that so people who are into data analytics they are very keen to use python as a programming language or perhaps SQL as well now JavaScript the entire worldwide web is wrapped around JavaScript whatever client side server you are looking at today it has a flavor of JavaScript in
            • 04:30 - 05:00 it okay like front end part whatever the client side of like there is server side then there is client side so whatever client side programs you are looking at there is a flavor there is a touch of JavaScript in it and Java and C++ on the other hand they are server languages like you can use Java and C++ like languages to create your backend servers Java can also be used for app devs like you can use Java native or you can use cotlin which is built on top of it so it
            • 05:00 - 05:30 has applications in application like app Dev whatever mobile applications we are using and normal web servers as well and same goes for C++ the benefit with C++ is that it's a fast language it's closer to the hardware and it is more performance efficient as compared to python which is built on top of C++ okay so we'll talk a little bit about what are the benefits of C++ because this module is all about C++ and my favorite language is also C++ if you have checked out my podcast about different
            • 05:30 - 06:00 programming languages you would know how much I love C++ so this is performance efficient and this is also server side language now I'm not going to waste a lot of time talking about different programming languages when this module is meant for C++ only now introduction to C++ I want to capture the essence of C++ like how C++ was born just take a brief understanding of what was the requirement why C++ was needed at that point in time and then obviously as I I told earlier I want to explain why C++
            • 06:00 - 06:30 okay what are the benefits of C++ so why don't we start with the benefits first and then we look at the history why C++ the first thing it's closer to Hardware okay closer to Hardware it is a lowlevel language as compared to python okay it's not a machine level language but it sits quite nearer to Hardware as compared to other programming languages closer to hardware and hence it is is performance
            • 06:30 - 07:00 efficient performance efficient to put it into basic word it's fast it has speed okay so wherever you want the executions to be fast for example you would look at trading firms okay they want their orders stock market orders for Equity future and options to be executed real fast in real time so they would prefer to use C++ as their language for the infrastructure okay now
            • 07:00 - 07:30 those who are doing competive programming also they would be aware about the benefits of C++ and how closely it is related to speed and execution so now since it's closer to Hardware there is another benefit which is the flexibility now you have you have more control over how you are managing the memory how you are managing the allocation of memory garbage collection and all of those features are more in hands with you as compared to some other
            • 07:30 - 08:00 programming language okay so memory management now some people would consider it as a con as well that you need to take a look at all of these things on your own whereas in Java garbage collection memory management all of that is handled by the language itself so it depends on your use case if you want that flexibility if you want that control over memory allocation garbage cleaning and all of that C++ can be a good language if you are too much concerned that how can I do this I don't want to to manage this part then you can
            • 08:00 - 08:30 choose other language like Java as well for your server side development so memory management is in your own hands and the main part like I will talk about it in like the conception of C++ as a programming language it is an objectoriented programming language okay
            • 08:30 - 09:00 which is a big plus and a reason why C++ as a programming language was born okay so this allows the real life entities to take shape in terms of programming languages and data structures like objectoriented programming like I will be covering a module for that as well to talk about the basics of objectoriented programming in C++ where we will cover it in much detail but for the time being let's just
            • 09:00 - 09:30 keep this in mind why C++ it's because it's an objectoriented programming language as well now looking back into the late 20th century okay the history of C++ development so in 1979 there was a PhD student who was working on his thesis which was about some simulations okay I don't have uh indepth understanding of what he wanted to do but he was working on a programming language named simula
            • 09:30 - 10:00 okay so as the name suggests he had some work to be done in the lines of simulations and simula at that time was one of the Primitive languages primary languages which dealt with objectoriented programming Paradigm okay so simula was an object-oriented programming language now at that time C++ didn't exist okay c as a programming language existed and with C it it didn't have any
            • 10:00 - 10:30 object-oriented programming Paradigm involved in it so C was fast okay and simula was not fast so now this person who was pursuing his PhD and he was writing his PhD thesis he thought how about making changes to c as a programming language so that it becomes objectoriented programming so now you will have both the pieces of cake that it's fast as well and its objectoriented programming
            • 10:30 - 11:00 as well so that's how C++ as a programming language took birth uh this person started working on it and then at that time it was called C with classes okay so some people would say that C++ as a programming language was born in 1979 when this person started working on C with classes but it was actually in 1983 that c with classes was rename to C++ and then the first edition was
            • 11:00 - 11:30 published in 1985 And Then There came on a flurry of different versions I'm not sure what version is going on right now perhaps it's C++ 20 or 23 I think 23 is still in beta or I I'm not aware because I have lost a touch with C++ I have been coding in Python for last few months so C++ a lot of versions keep on getting rolled out and the main benefit of C++ is the community support okay so let me just add the up in the Y part as well
            • 11:30 - 12:00 along with the speed along with the object objectoriented programming and all of that Community Support is a big plus like lots of programmers code in C++ so if you have any doubt if you have any confusion you can use platforms like stack Overflow and all of those platforms to get your doubts clarified and the documentation is obviously topnotch okay so Community Support is something why I like C++ a lot Community Support is
            • 12:00 - 12:30 Rich okay so now we have covered the history we have also covered what are the advantages of C++ now let's move to the main part why we are all excited we will start coding in C++ we will understand the structure of a C++ program we will write and compile our first C++ program so to all those who are beginning with C++ as a programming language will start from scratch okay so you need not worry any anything at all that hey I don't know the syntax of C++
            • 12:30 - 13:00 hey I don't know how to write a program how to compile it how to execute it and so on we will start everything from zero and then we will build the basics so let's first understand the C++ code structure and then we will write our first program now this is what a code structure looks like it may be overwhelming but don't worry be with me we will go Pace by Pace slowly trying to understand what all these things mean okay so the first part is header declaration or including
            • 13:00 - 13:30 headers okay don't worry what headers are we will talk about that as well at this moment let's just understand what all different portions are there in a C++ program okay so what is necessary is this int main function don't worry what a function is as well we are going to cover that as well so int main function is really important because when we execute our program the comp ER or like
            • 13:30 - 14:00 the binary will look for the int main definition and the execution of the code will start inside it okay whatever code is written inside the int main function that is going to get executed so this is really important without the int main function your C++ program can't get executed okay don't worry if you don't know what is int what is main what is return zero step by step we will understand all of it but at this moment just understand your program will not execute without this no
            • 14:00 - 14:30 execution without this okay now let's just take a step back and understand why headers are needed okay so as I told you a lot of work has already been done since the 1980s on C++ so you need not write all the code on your own you can take use of the libraries which are already existed okay let's say you want to find out Max of two numbers okay so the code for that
            • 14:30 - 15:00 already exists you don't need to rewrite that code and this code is present in some libraries which we can include using their headers so that is where the headers come into picture you can include the respective headers for whatever utility your code requires and then you can use it directly without having to copy paste or write it again okay so that's where the headers come into rle if you don't need to like if you don't require any utility from outside your code it's completely fine you don't need to include it okay this
            • 15:00 - 15:30 is not necessary first of all this is not necessary and then there are some Nam space declarations and there are other class and function definitions at this moment don't worry about it we are not going to talk about this in detail and you won't require it for this particular module but just to give you a hint that such apart from the headers and apart from the int main function there can be a few Nam space declarations and there
            • 15:30 - 16:00 there can be a few classes few functions and these elements can exist in your C++ program but for the time being we are not going to dwell into all of that so this is also optional once again this is not necessary all right now this is how the structure of a C++ program is broken down into now let's move on to writing our first program okay now this is how compilation Tak takes place I will explain that but
            • 16:00 - 16:30 let's first write our code what I'm expecting from you is that you have access to terminal either it's your MacBook or you are using a Linux machine or it can be any other machine so this is what a terminal would look like and using this mkdir syntax I'm going to create a folder like in programming words we call it directories which is equivalent to folders okay so I will just name it intro to C++ okay now using CD command I can move
            • 16:30 - 17:00 to intro to C++ directory okay now I'm using a Sublime Text Editor for writing my code because it's one of the most basic ones but if you have access to visual studio or any other sophisticated code editor as well feel free to use them they are very powerful okay I I'm not recommending this particular uh code Editor to anyone it depends on your use case it depends on whatever your muscle memory is and what is more comfortable to you okay okay so now I will just write intro. CC
            • 17:00 - 17:30 now cc is the extension of C++ programs so okay I wrote into intro. CC okay now we'll start writing our first code what okay let's just move back to the syntax and let's start adding pieces step by step okay so headers are not necessary the Nam space declarations and other classes are also optional and what is necessary is the int main function
            • 17:30 - 18:00 okay now don't get overwhelmed by what return zero is doing over here and so on we will be covering about that we want to print like okay what is going to be our first program our first program is going to print hello world which is usually the first program of other software Engineers as well like my first program was printing hello world okay so we want to print hello world
            • 18:00 - 18:30 okay so for that we are going to use a utility provided in some other Library which is cout which is used for printing outputs on the terminal okay so we will cover C out in detail when we are talking about input and output streams but right now it's important to understand that c out is used to print something to the terminal okay from memory it goes to the output device whatever device we are using over here it's a screen it's a terminal okay now we are going to just write
            • 18:30 - 19:00 hello world and then we will add a new line okay we will cover what a new line is as well but let's just try to compile the program okay now g++ command is used to compile a c uh C++ program so intro to C++ we will try to compile now over here there is an error it says C out was not declared in this scope Andel was not declared in this scope okay now what it means is that we used some utilities which were not defined in our program and since I know
            • 19:00 - 19:30 I used it from some other Library we are going to include it as a header okay so let me just include it hash include now the header is iost stream okay so now it should get compiled now if you see again it's giving an error and it says see out was not declared in this scope did you mean
            • 19:30 - 20:00 STD see out now what STD is it's the standard template it's a standard Library which we should be using like that's the Nam space so if you remember the structure of a C++ program there can be some namespace declarations so using namespace STD will sort this thing for us because we are using the see out and endl utility from the STD name space okay so this is just to tell the compiler that hey if you find something which is not using the name space explicitly we are using a namespace STD
            • 20:00 - 20:30 and please try to check if it exist in the STD namespace or not there can be more than one name spaces but over here we only require one okay now it is compiled and now let's try to execute it so before that let's take a look at what the different files are inside this directory so intro to CC was our main code and a. out this is the executable which is created when we compile a C++ program by default okay so now I will just write the name a. out and then this
            • 20:30 - 21:00 should get executed right you can see Hello World on your screens and it executed our program as it was intended to so now you might be wondering how the compilation and everything took place so let's take a step back and try to understand this entire process a little bit so this is our source code okay Prue one. CPP this is an example flow so over here our name is intro docc you can use CC as the extension for a C++ program you can also
            • 21:00 - 21:30 use CPP as the extension for a C++ program both of them are fine now the first step is pre-processing the code so there is a pre-processor which tries to expand the header files that we have included so if you notice we used the header file by using hash include command Okay hash include statement so we did iio stream which was used for and and see out okay so now when we add a
            • 21:30 - 22:00 header file in our program it refers to some Library which is already there in our C++ Corpus so it tries to fetch that particular code and tries to expand it so now if you were to look the file like how it looks after the C++ processor processes it it will just write the entire code of like whatever was there in IO stream Library it will try to expand the entire code and put it into to our file okay so this is like that's
            • 22:00 - 22:30 how pre-processing happens and then it says that it's an expanded source code file what I talked about it's a temporary file and can be printed as well if you wanted to now here is where the compiler fits now you might be wondering that entire process is called compilation and then there is a subprocess within it where the compiler actually executes so that's right I mean even though the entire process is known as compilation this is where the actual compilation happens and then there are some other processes associated with
            • 22:30 - 23:00 creating an executable file now compiler creates the source code after pre-processing into an assembly level language okay now s is an assembly level language now this is not exactly a binary code this is not a executable file it converts it into a more like it converts it into a language which is closer to the hardware there would be some some instructions about how the data needs to move from one register to
            • 23:00 - 23:30 other register and how the hardware needs to execute it okay so this language is understandable by the hardware now assembler runs on top of the assembly level program and then converts it into an object code which is what is going to be executed so this is a binary program which we can't understand okay humans can't understand it assembly level is still understandable by humans and machines both of them all right so so the first two files source code file and expanded
            • 23:30 - 24:00 source code file only humans can understand it assembly level language both humans and Hardware can understand it and object code can only be understood by Hardware humans can't understand it because it's only bytes now the last step over here is a Linker okay what the Linker tries to do is whatever the object code file was
            • 24:00 - 24:30 created whatever the object code was created in the earlier step it tries to link different Library functions for example in our code we used C out and NL so whatever code is required for these two functions only that will be linked with our object code and then an executable file is created okay this is the ultimate step this is equivalent to the a.out file which was created now this is implicitly created if you want to create some other object code we
            • 24:30 - 25:00 could tell the compiler that okay hey create this part like create an executable file with this particular name so let's try to do that if I'm not wrong hyphen o is used to give that name so when we are compiling we can just let the compiler know that please use some other name so over here we want to use the name intro so let's just compile it and let's look at the files that are created so now as you can see a do out already exist from the previous compilation and it has Al also created intro so now if we try to execute intro
            • 25:00 - 25:30 this also prints hello world so in this way you can give a name to your executable file if you wanted to but a. out is by default okay so a. out is default and hyphen o and some name is used to give the name to an executable file so this is how the entire process of compilation looks like and we also return our first program so many many congratulations to all those who have returned the first program with this
            • 25:30 - 26:00 particular tutorial if not I would seriously recommend you to pause the video at this stage and write a program on your own because watching a tutorial is one thing and converting the things that you are learning over here into real code is what is going to help you grow okay so now let's take a look at some of the parts of a C++ program okay I will just write this particular code which is there on the slide into our intro code itself itself I will remove the hello world
            • 26:00 - 26:30 statement okay now I don't need both of these as well we will just have a int main program and this is a comment int a don't worry what in a is I will talk about that when we talk about variables now if you notice this is a comment so whatever is followed by double forward slash okay this is double forward slash whatever is followed by that that is a commment it doesn't get
            • 26:30 - 27:00 executed by the machine first of all it is ignored completely whenever the compilation process happens this is only for humans understanding if we wanted to explain what a part of code is doing then we can use comments to add that description over there this is ignored both of these statements are ignored by our compiler and this is a statement is also ignored by the compiler now over here I'm using the statement I
            • 27:00 - 27:30 mean I'm using the com uh comment over here to explain that whatever is covered in red on the screen it is a statement okay int a equals to 5 that is a statement now semicolon is the heart of a C++ program whatever code is mentioned before a semicolon that forms a statement so a statement is a building block it's a
            • 27:30 - 28:00 fundamental unit of any C++ execution so one statement is one step in a C++ program okay so statement is a fundamental unit your code is broken down into multiple statements and all of the statements will get executed sequentially as they are mentioned now I have been holding you to understand what return zero means so
            • 28:00 - 28:30 over here we are returning an integer this is what a return type means we will cover that in much more detail in our topic about functions but here return zero means the program is getting executed successfully if there is some other error it will return one instead instead of zero which means that there is some issue with your C++ program okay so at this point I think this is a good place to understand understand what the comments are what the statements are and
            • 28:30 - 29:00 what the wide spaces are okay so in C++ program as if you know if you remember previously like we used C out and then we printed hello world and then we used endl okay now what does NL do it creates a new line okay this can also be replaced by sln which is an escape character Okay so instead of endl you could have used the sln as well so if
            • 29:00 - 29:30 you're looking at the screen right now there is a sln instead of NL and it will do the exact same thing so that is a widespace character sln means add a new line after this so let me just add the name space which we removed earlier and let me also include the header file for this hash include IO my bad IO stream okay so now I mean whatever is return
            • 29:30 - 30:00 between the parenthesis this is the name of the header okay IO stream whatever comes between opening uh triangular brackets and closing triangular brackets that is the header and hash include tells the compiler to include this particular header okay so now if I try to execute this again let's just compile it okay and let's execute it it does the
            • 30:00 - 30:30 same thing okay if if it is sln or if it is endl it has the same behavior you can add add a space in between as well you can add tabs also in between that's completely normal now if you look at the slides there are some spaces involved in the demo code as well in the example that I have provided there is some space between int and a between a and equal to and between equal to and five so so these two spaces are not
            • 30:30 - 31:00 required you can get rid of them but the space between int and a is required it's because int is a keyword okay it's reserved and a is name of a variable we'll cover both of these topics in a little detail but over here understand that the space between int and a is required because it tries to add a meaning but if we were to replace int space a space equal to space five and a semicolon with int
            • 31:00 - 31:30 a equal to 5 with no space in between it's completely all right okay let's let me just make these changes in the code and then I can show you what space is important and what spaces not so in the code I have removed spaces before and after equal to and let me not add any space here as well so if you're looking at the code I am breaking the entire code down into a single line okay this will also get
            • 31:30 - 32:00 executed you see it has the same execution so even if you are to add spaces or tabs that's just for the human understanding so if you can see on the screen right now it is completely cluttered like I can't understand what the actual code is code is so I will try to indent it I will try to like write all of the statements in different lines so that a human being can understand it it is not an issue for the machine to compile it it knows where the semicolons are this means there is a statement where the forward slashes are it means
            • 32:00 - 32:30 it's a comment and so on okay it understands everything but but for a human to understand Aesthetics are important to a code okay so over here the tab is only for indentation I could I could remove this tabs get rid of the indentation and then compile and run it it would run as it was doing previously but this tab helps me with the indentation and understanding of what part is in this particular main functions scope so we have understood
            • 32:30 - 33:00 what the comments are what the statements is what is the importance of Whit space where the white space is important where it is not and we have also written our first C++ program so now let's move to what different data types are there in C++ so if you observed earlier we have already used int data type which is an integer okay so those who are completely new with programming let me just explain what like what bits and bytes are so every
            • 33:00 - 33:30 program is first of all it's converted into zeros and ones okay now each of these values are stored in a bit what a bit is it means a bit can hold zero or one this is a binary language okay now a group of bits is what a program is made of so 8 Bits is equivalent to 1 bite okay this is not B bite this is byte
            • 33:30 - 34:00 bite this is different than the bytes we take while eating food so 8 Bits is one bite so how much data can one bite hold okay so one bit can hold two numbers zero or one and whenever I'm talking over here this is the binary language I'm talking about I'm not talking about the mathematics that we have pursued so far so if I wanted to use eight bits then for each of the bits I have an option to add two values either zero or 1 so 8 Bits will hold 2 ^ 8 values which
            • 34:00 - 34:30 is equivalent to 256 numbers so 1 bite can hold up to 256 different values so this is permutation and combination normal mathematics 11th and 12th standard as far as I remember so one bite can hold 256 different values so if you look at care over here so there is something known as ask key code which represents different types of characters you can add in a program so an ask ke code has values from 0 to 255 so this
            • 34:30 - 35:00 has some special characters this has alphabets both Capital both small it has digits it has wi spaces and all the characters which you can use in a program okay they are captured within this 256 values so how much data is required to hold a character it's equivalent to one byte okay because one bite can hold 256 different values so you can hold all the aski characters in one bite and hence the data type for for characters if you wanted to represent some data for characters only one bite
            • 35:00 - 35:30 is required now what is a Boolean a Boolean means zero or 1 true or false okay true means one a Boolean means true or false and true is represented by zero and false is represented by one so in theoretical sense only one bit is sufficient to hold this values but in reality if you see one entire bite is allocated to it it's because of the memory management in the modern systems
            • 35:30 - 36:00 that like theoretically even though we can hold it in one bit you would see that it occupies the entire bite so all the eight bits it would look something like this okay these are seven zeros if I'm not wrong yeah so this is how it would be represented this is true and this is false okay so one Bool will like even though it OCC it requires only one bit it will also hold one byte same as characters now there are a
            • 36:00 - 36:30 few other data types to hold the numerical values that is int long long int float and double int and long long int are used to capture the whole numbers negative numbers zero and positive numbers as well and float and double are required for decimals okay so let me just add that this is for decimals and int and long long int are for whole number
            • 36:30 - 37:00 numbers now there are a lot of other data types like short int long in unsigned integers as well but for the scope of this particular module let's not go deep into it because these few data types are going to be sufficient to understand what different types of data types can exist so as you can notice over here int data type captures four bytes okay these means this means that four bytes which means 4 into 8 32 bits are
            • 37:00 - 37:30 there okay which means it can hold 2 to the^ 32 values all right but integer doesn't hold just positive values it also holds zero and it also holds the negative values so if you have a look at the range it holds from Min - 2 ^ 31 to 2 ^ 31 - 1 including 0er in between so in total it holds 2 the^ 32 values along with ative positive and zero and similarly for long long it it is of 8
            • 37:30 - 38:00 bytes length which means 64 bits and hence this range now for float and double float is equivalent to integer in the sense that both of them hold 4 bytes each now if you want normal like decimal capacity of 6 to 7 decimal digits then float is sufficient but if you want something very precise for scientific purposes then you you should use double because it can hold up to 15 decimal points okay
            • 38:00 - 38:30 so I think this part is sufficient to understand what all different primitive data types are if it was let me just explain in a little brief what unsigned means unsigned means there won't be any negative values okay this will only hold positive integers so if it was unsigned int then it will store from 0 to 2 ^ 32 - 1 okay so these it it won't store negative
            • 38:30 - 39:00 values and hence it gives you more capacity for positive numbers so if you were to use if for your use case if you wanted only positive numbers then you could have used unsigned in to get more capacity for more range and same goes for long long int as well all right so this is this is the place where we cover what different data types are okay Now we move on to the next part where we talk about different variables
            • 39:00 - 39:30 okay so what is a variable a variable is something which holds some memory okay if you remember we used int a right so a over here is a variable [Music] name okay in shows what the data type is as we talked about earlier so this means that a holds 4 bytes in the memory okay so
            • 39:30 - 40:00 whenever we create a statement like this whenever this statement is executed it tells the compiler that hey please allocate four bytes of memory to me and the name of this particular memory would be a in real a doesn't exist okay it's just a label like my name is anul so anul is just a label for me but in reality I'm just a human being I just have some uh features of human being like I have two eyes one mouth and so on so similarly an integer like a is just
            • 40:00 - 40:30 an integer and a is the name of that particular entity okay so this is what a variable would look like like instead of in it could have been a long long int it would have more capacity it would be holding eight bytes instead it could have been a Boolean a character whatever we wanted okay so over here just to keep in mind a is not an actual physical thing it's just the name of memory which is allocated so let's say in the background
            • 40:30 - 41:00 there is some memory allocated and each of this block is equivalent to 1 by so this in fact is 4 bytes now these four bytes are continuous memories okay 1 by 1 by 1 bite and one bite all of these bytes are in contiguous addresses and this entire four bytes are allocated to one integer and the compiler knows that if we wanted to access it by using the name name a then it means we want to access the values which is held by this
            • 41:00 - 41:30 particular memory okay we will talk about addresses and memory and all those in next module where we will talk about pointers and addresses but for the time being let's just know this holds four bytes and a is just the name of the variable in order to access whatever is placed inside that address now this is what I actually talked about data type is int variable name is a and this is the value so if
            • 41:30 - 42:00 you remember earlier okay we said that there will be some memory allocated to it now in that memory we want to assign the value five to it so if you were if you had knowledge about what binary language looks like then five is represented by 101 in B binary language okay binary language now you would be like hey anul this require was only three bits why are we storing it in four bytes okay but
            • 42:00 - 42:30 this is how the nomenclature is if we are representing it by int it is going to store it in entire 32 bits or 4 bytes so whatever things you cannot see over here there are zeros in front of it so there would actually be these are three numbers so there would be 29 zeros followed by this three bits okay so this is how in memory it will look like so so there will be five zeros followed by 1 0 1 and all of these
            • 42:30 - 43:00 numbers would be zero all of the previous bites would be zeros so this is how in memory five will be stored okay so now just a bit of technical jargon just a bit of technical nomenclature so when you write int a what the compiler does is it creates some memory okay memory exist okay it doesn't create memory it allocates the memory I should have chosen better work words so it allocates four bytes and tells that this four bytes belong to a
            • 43:00 - 43:30 okay whenever we want to access a we will try to find what value is stored inside those four bytes so memory allocation happens here all right right now no value is assigned to it so it will use the default value zero so even though we have not mentioned anything in the memory like let's say these are the four bytes everything will be filled with
            • 43:30 - 44:00 zeros okay all of these are zeros so now we can we can initialize it by using this particular syntax variable name equals to Value this can be any value instead of five you can store 100 okay you can store 200 but now let's assume one thing we know that integer
            • 44:00 - 44:30 holds four bytes what if we try to assign it to a value which was greater than 4 bytes okay let's try to explore that part and let's see what happens let me just get rid of C out in the program let's get rid of the name spaces and the header files as well okay so now instead of five if we I were to add a very big value which an integer can't hold okay so let's try to compile this program what happens let's see what happens so
            • 44:30 - 45:00 now we can see on the screen it shows me a warning that integer constant is too large for its type okay this means that whatever number I added over here it cannot fit in four bytes and it also says overflow in conversion from long in it means that a long in data type is sufficient for the number that I have mentioned over here but since I have explicitly mentioned that this should be an integer what it will do is it will convert this number into an integer so it will be
            • 45:00 - 45:30 assigned to some garbage value it will wrap it like this is known as an overflow condition first of all whenever you assign it to a value which is larger than the capacity of that particular variable it will lead to overflow okay so just assume that instead of 32 bits in an integer you for example added 60 bits so there will be some part of this number which will flow out of the four bytes and will try to minimize it
            • 45:30 - 46:00 restrict it to 32 bits I don't know what logic is used behind it maybe it takes the last 32 bits maybe it takes the first 32 bits or maybe it does some processing and converts it into 32 bits but what needs to be understood over here is that the code will not execute as you intended it to so let us just try to print what the value of a is okay so we will just try to print a and see what happens okay so now let me
            • 46:00 - 46:30 add back the header files if you notice the header files and the namespace Declarations were not required in the previous compilation it was because int a equals to 5 and whatever zeros are there it doesn't require any library or header file now I will not get rid of these two values because I need to add it again and again and remove it again and again so let them be present even though we require it or not so let's just try to execute this
            • 46:30 - 47:00 and see if you notice in the error or in the warning actually error is different from a warning error means your code can't execute okay with errors you cannot execute your code with a warning it just gives you a sense that okay your code might not perform as expected so be mindful of that so it says overflow in conversion from long end to int changes the value from whatever this value was I'm not sure to zero okay this is how it's processing maybe it's converting to zero okay let me just put a smaller
            • 47:00 - 47:30 number in this I'm not sure if this fits into an integer or not my hypothesis is it still doesn't and over here it says that it overflows from an long int to an integer and changes the value from five whatever it was to - 7433 09 312 okay so in this case it's not redefining it to zero it's not assigning to zero it's assigning it to some garbage value so just a piece of
            • 47:30 - 48:00 advice that be cautious whenever such a situation happens and you know what the correct data type is let's say instead of int I were to use long int okay let's see if this issue is still exist or not okay now it is not throwing any error any warning and let's hope it prints the same value yes it does let me just compare it I have copied it and okay now I pasted it yes no extra digits
            • 48:00 - 48:30 are added to it no unnecessary digits are removed from it so both of the values were the exact same so this is a blueprint of how database declarations happen now as I was talking some technical jargons over here so let me just get rid of all of these values and let's discuss the technical jargons in a little bit so so now the technical jargon or the nomenclature here says that when int a
            • 48:30 - 49:00 is there this is just a declaration okay we are not assigning it any value we are not defining what the like what a points to okay so this is just a declaration which means it will allocate some memory to it but there is still no value in it so by default it will be zero now this is initialization we are updating the value Val of a for the first time so this is known as initialization and if we were doing both
            • 49:00 - 49:30 of these things in the same statement then it would have become a definition it does both declaration as well as initialization okay so I think this is sufficient to understand what the nomenclature is in C++ or programming now these are some rules for declaring a variable name okay it should contain only letters which can be a to zed and this includes both capitals and small alphabets it can contain digits and it can also contain
            • 49:30 - 50:00 underscores so now let me just try to create a variable with at the rate in between so let's say if the name was a at the rate okay I'm not sure if this will compile or not okay it says stray at the rate in the program let me just try to rename it to something else and let's also use underscore in it let's see if it allows me to compile it or not not okay it says a was not declared in the scope it because it's trying to access a variable
            • 50:00 - 50:30 which we have not declared so let's just try to update it yes it runs as expected so this hypothesis is correct now it is case sensitive so if there was something like able a and then double A with capitals these two would be two different integers pointing to two different me memories in your RAM okay so both of them are different variables so be
            • 50:30 - 51:00 mindful of that now it doesn't contain any white space or special characters okay so this should not be there just make sure you understand what doesn't mean over here we should not add any wi space in between we should also not have any special character must begin with a alphabet or an underscore it cannot begin with a digit okay so you can just try it out in your laptops try to name a variable starting with 0 to 9 anything and it won't let you name it cannot use
            • 51:00 - 51:30 C++ keyword so if you remember I said int was a keyword so there are some special names which are assigned for C++ keywords int long long int for class double float all of these data types all of these other spatial functions and so on those are reserved as some for for some different purpose so you cannot use them for variable names so these are some rules we should which you should keep in mind when you are
            • 51:30 - 52:00 naming your variable okay so now let's move on to input and output operations so we have already used it okay first of all we have already used C out so in some sense we are already aware what input and output operation means but there are two types of streams like there are more than two types of stream objects there is also error stream object but we are not going to talk about it there are input stream objects which takes in some value from a device and it all assigns it to a memory allocated inside the machine okay so
            • 52:00 - 52:30 from device the bytes flow into memory okay this is input stream and we will use the C in keyword for that now what is an output stream it flows the me uh flows the bytes from memory to device okay and we will use C out keyword for this now if you already coded in C previously then you would know there are functions known as scan F
            • 52:30 - 53:00 and print F okay so scan f is equivalent to C in in C++ and print f is equivalent to C out in C++ so we can use the same like similar functions like we can use C in to take an input and C out to take an output so let's just try to take an input instead of assigning the value to a let me just rename it to a so that it's easier to read okay so instead of assigning a value over here let's just Alo like let's just declare it so in
            • 53:00 - 53:30 memory some space will be allocated to it and then instead of updating it initializing it let's take it from the input from the user Okay add value for a so let's try to just compile it and we will execute it so now it printed add value for a now it has a c in command in the code so it knows that it has to wait
            • 53:30 - 54:00 for a human output okay so it will wait for my output I have typed three and then as I press enter it will try to read the value of three from the device assign it in memory to the space which was allocated to a and in the next statement it will try to print the value of a so as you can see on your screen after I pressed enter it executed rest of the code the code was blocked until I gave gave it an input and now it has printed the value of a so this is how input output operation happens in
            • 54:00 - 54:30 C++ and to the next part let's talk about some of the operators now you would know by definition in mathematics there are operators like plus minus and so on so operators work on operand okay so there can be two operant if we are using a binary operator like plus minus multiplication division or modulo it can have a single operand if it's a unary operator we will talk about that as well but these are unary operators which are suitable for only one
            • 54:30 - 55:00 operand so when I talk A and B in the explanation over here understand that those are two operant on which an operator is operating and if there is some let's say this is not a so when I talk just about a it means I'm talking about a unary operator and unary operand so arithmetic operations is quite explanatory like these are mathematical operations ation which take place between A and B so there can be addition subtraction multiplication division and
            • 55:00 - 55:30 modulo okay so I don't think I require to explain that in more detail now I will talk about assignment oper operators and unary operators after I explain the other ones now what are relational operators okay now this is double equal to sign means it tries to compare two values it tries to compare A and B and checks for its equivalence Che X for its equality okay so now if a is 4 and B is 5 this will return false okay
            • 55:30 - 56:00 so the output type of Rel relational operators is a Boolean okay and now I think this becomes rest of all the operators become quite explanatory that double equal means it checks for its equality not equal to now explanation uh the exclamatory mark this is equivalent to not so if we to use not equal to Instead This would have been
            • 56:00 - 56:30 true okay I'm not writing the code separately for this because I think you can try to explore it on your own you can just pause the video at this place try to write this statement okay int a = to 4 int B = to 5 and then you can just try to print what is uh what is stored over here a equal to equal to B so this will either print zero or this will print
            • 56:30 - 57:00 false I'm not sure what it will print because 0 is equivalent to false so it is possible it might print zero as well so you can just try to execute this code and see for yourself what the outputs are now this is the greater than symbol greater than equal to less than and less than equal to we have been using this relational operators for a very long time so I don't need to explain all of these again now logical operators require the operant to be Boolean values okay so now this double
            • 57:00 - 57:30 ment operator means end so if both of them are true then only the value of this will be true if any one of them are false then it will return false so at this point I am assuming that you are aware about how end and or and all those logical operators work I'm just here to explain what is the equivalent operator which we can use in C++ language now over here you can see a not operator as well now this is a unary operator so if
            • 57:30 - 58:00 I will to mention not a equal to equal to B okay so first of all it will try to resolve a equal to equal to B this is equivalent to false and when we will expand not this will mean negation of whatever the Boolean was there so not is also meant the oper end for not should be a Boolean value so it will try to reverse whatever Boolean was there if it was false it will turn it to true if
            • 58:00 - 58:30 it was true it will turn it to false okay so this closes logical operators and now talking about the bitwise operators bitwise operators are applicable on the bits let's say this was 101 which is equivalent to 5 now this is in binary language so now if I were to use B and this bitwise operator followed by a one this means that this binary value
            • 58:30 - 59:00 should be shifted by one place okay we will add one zero after it all right so this will convert 5 into 10 so basically this operator will multiply the opend by two and if we were to use the other operator it will try to divide its value by two so if 101 was there this operator will convert it into 1 Zer the one is shifted to the right and it we get rid of it and only 1 Zer
            • 59:00 - 59:30 remains so 5 ided by two its value is two okay it doesn't convert it into a decimal value it will try to seal it okay so this moves the bits by one place like if the other operator oper end was one if instead we were let me just remove the other stuff so that it's easier to understand so now B so if this was our expression it would mean that 101 should be moved by if I'm not wrong
            • 59:30 - 60:00 a was having four and B was having five this should move 101 by four places so our output for this would be 5 followed by four places which is equivalent to 5 into 2 into 2 into 2 into 2 this is 5 into 16 which is equivalent to 80 so a new value will be 80 this this is equivalent to 0 so now you might be confused what single Amper sand pipe and carat means
            • 60:00 - 60:30 so single M percent is also equivalent to double MC but double m per the operator operates on Boolean values a single m per operates on bits okay so if it was 0o and one this will mean like and means both The Operators should be equivalent to one both the bits should be one in this case only it will return a one in all the other cases 0 and 1 1 and 0 0 and 0 it will return the Bit
            • 60:30 - 61:00 Zero okay now just to keep in mind I will reiterate this again the inputs are bits and the outputs are also bits in logical operators the inputs are booleans and the outputs are also booleans though we can represent booleans by bits and bits by booleans let's not try to replace when like replace these operators in the ual code if the operators operands are meant to be bits then let's use bitwise operators
            • 61:00 - 61:30 if the operands are meant to be booleans then let's use the logical operators only now or is also explanatory because we used it earlier in logical operators now this carrot means zor okay now zor means if the parity of both the bits is same let's say it was Zero zor 0 and one zor one it would return the bit one if the parity was something different like 1 and zero both of them are different parity it will return a zero okay so
            • 61:30 - 62:00 bitwise operators is also done now let me just remove all of these details again let's talk about the assignment operator so assignment operator as explanatory like the equal to sign assigns one variable some value okay so if we had to do a equal to B so what it will do is it will update the value from 4 to B so now before it was holding value 4 and now it is holding the the value five so in this way we can update it to any value this could have been a equal to 6 as well this would also
            • 62:00 - 62:30 update it it would assign the value now what does plus equal to mean if I were to use plus equal to 5 this is expanded to AAL to a + 5 what it does is whatever the right operand is it adds that value to the left operand okay but we cannot do obviously we cannot do 1+ equal to 5 okay this means we are indirectly saying 1 is equal to 1 + 5 which is a mathematical fallacy okay so
            • 62:30 - 63:00 instead let's remember that in assignment operators the left hand side which is the LHS it should always be some variable okay now all of these like over here we used a + equal to 5 now this plus can be replaced by any of the arithmetic operators okay any of the Ari Matic operators or any of the bitwise operators and so on okay let's not replace them by logical operators and
            • 63:00 - 63:30 relational operators because they are meant for booleans okay like the output of relational operators is Boolean and the input of logical operators is Boolean so we will use arithmetic operators and bitwise operators in assignment operators as well we can use them okay so we are done with assignment operators and now talking about unary operators now what does A++ mean A++ means we will add the value increment the value of a
            • 63:30 - 64:00 which means that if a was five earlier now a would be six okay now this Plus+ can exist before a as well and after a as well so now if for example let us try to take a complicated example if I were to do a is equal to b++ okay so what it indirectly means is that first we will will try to assign the value of a to B and then we will update the value of B If instead of b++
            • 64:00 - 64:30 it was a = to ++ B what it does is it will first increment the value of B which means that it will increment the value of B to six from five earlier it was five it increments it to six and then it will assign that incremented value to a okay so Plus+ before the variable name means that before we use it somewhere the value of B will be incremented and same goes for minus minus it tries to
            • 64:30 - 65:00 decrement it and if the Plus+ if the unary operator is followed by the variable name it will first assign that value to a and then it will be followed by the increment so this is what un operators do now I think we have talked about a lot of operators in detail so you should be good to go for a lot of operations you can just take an input A and B and then print the summ or subtraction of A and B and you can try out various cool things
            • 65:00 - 65:30 now okay so now coming to the last part of this first module which is decision making so now here we come to the first part of a C++ program where we'll try to do something cool okay A plus b is cool enough but let's try to do something cooler for example like whenever you are going out whenever I go out in Bangalore I check the weather okay if weather is cloudy is cloudy or it is
            • 65:30 - 66:00 raining take umbrella okay so when will I take an umbrella it would only be when the weather is cloudy or it is actually raining if that condition is not true then I won't take my umbrella out with me okay so there are lots of decisions that we make in any program it can be a C++ program Java python SQL or anything at all we will be
            • 66:00 - 66:30 making some decisions and to make this that those decisions we are going to use conditional statements so in C++ there are conditional statements like these are keywords if else both of them are keywords if and else these are keywords okay so these are reserved we cannot name variables by these keywords so this is equivalent to the human language like
            • 66:30 - 67:00 this is equivalent to the English language that we use if followed by some condition okay now this condition should result in some Boolean value okay it can be a greater than 5 or it can be a and and B in this case both of them needs to be Boolean A and B anything at all the output should be something Boolean okay if condition then we will try to use the braces we will try to do something okay
            • 67:00 - 67:30 we can execute any part of the code whatever we wanted to do followed by that condition so we can do something we can execute some part of code okay it can be if a greater than five then update the value of a by 10 I don't know okay I'm just writing something and if the code is like this like there is a single if statement then it will enter the block okay this is known as a code block whatever is between the curly braces the opening
            • 67:30 - 68:00 braces and the closing braces if anything is there that piece of code will get executed that block of code will get execute if that condition is not successful then that code block will not get execute whatever is there above this code block and whatever is there below this code block will get executed it will enter this code block only on the success of this condition only if this is true then this will get executed otherwise not so now let's just try to
            • 68:00 - 68:30 write some code for this okay let's not take the value of a from the user let me just Define it to five we can use an integer instead of long in so let's just add a statement if a is greater than three then we will print greater than three okay I'm just writing something for
            • 68:30 - 69:00 explanation or now there is no else part to it okay this it is not this or that in this case it will just try to execute the next statements because we are not writing any else uh syntax over here so in this case we'll just change the output to normal execution okay so let's just try to compile it very quickly and execute it so since a is equal to 5 it also prints
            • 69:00 - 69:30 greater than three it will print normal execution in any case let's just try to change the value of a from 5 to 2 in this case this command fails a greater than three fails it will be equivalent to false so in case of a false condition it will not try to execute anything which is within the if block okay so let's just try to quickly compile it and then we will print it so as you can see it doesn't print the greater than three statement it will only print normal execution okay so now let me also add
            • 69:30 - 70:00 else part okay so in this case it becomes this or that if a is greater than three then do this else do that okay it has to do one of the two things because a condition can either be true or false so in case of true it will execute the if Block in case of false it will execute the else block so we'll just write less than three okay so let's compile it again and run it it prints less than three and normal
            • 70:00 - 70:30 execution now let's just once again for my satisfaction let's just try to update the value to four and then run it again it prints greater than three so in any of the cases it's going to print something okay so if you check over here in the slides it says if the condition is true if the condition is true it will execute this and okay I did a typo if the
            • 70:30 - 71:00 condition is true then do something and if the condition is false okay whatever this condition was if it is false then execute the other part whatever is followed in the parenthesis whatever is between the parenthesis after the else block okay but now here there can be multiple conditions as well for example if a is greater than 5 then do something in this we can have nested if and else
            • 71:00 - 71:30 as well okay but there can be a chain of conditions as well it can be else if we can use else if instead now if a is greater than five do that then let's use another condition else if a less than three do something else okay not so good drawing all right so now if a is less than three it will execute this code
            • 71:30 - 72:00 block okay whatever the condition is if it is true then it will execute this code block if the first condition is true it will execute the first code block okay if the second condition is true it will execute the second code block but now if I were to change it okay let's say if I changed it to oh my bad if I changed it to a greater than 8 okay now let's say if the number of like if the value of a is equalent to 9 okay it will succeed the
            • 72:00 - 72:30 first condition okay which means the first block will get executed and it will never move to the second block the else if part will completely be be ignored because else means if it is not greater than five but in this case it is greater than five so it will not even consider this second if block at all so you should be very cautious how you are defining the conditions if you wanted to cover the a equal to Great uh a equal to a greater than 8 part then it should have been within the first block itself
            • 72:30 - 73:00 so let me just try to cover that thing in our code a greater than 5 so we will print greater than three and we will also add another condition for a greater than 8 okay if you notice over here the white spaces are not important before and after the operators we can just print greater than 8 okay so now let's just keep it equal to
            • 73:00 - 73:30 six so in this case so just to show you so there are three code blocks in this case if a is greater than five there is some code block inside it we are trying to add another code block for a is equal greater than 8 so this is code block one this is code block two and after that we are also having a else statement so this will be code block three so when will One be executed one
            • 73:30 - 74:00 will be executed any time when a is greater than 5 two will only be executed if it enters the first block which is on a greater than 5 and also if it is greater than 8 so let's say if it was some number like 9 10 11 and so on it would have executed both first block and the second block and the third block would have been ignored so let's just try to ex execute this thing a is equal to 6 in this case it will not enter the second block because when we try to compare it with a
            • 74:00 - 74:30 greater than 8 it will fail because 6 is not greater than 8 this will lead to a false and we will not enter the second block so let's try to just run the program quickly you can see it executes the statement in the first block but not in the second block and it ignores the third block altogether now if I update the value from from 6 to 9 it should execute both of the statements in the block one and in the block two so yes it does as we told it
            • 74:30 - 75:00 executes both of them so in this case you can add any number of nested conditions there can be any if else statements inside the If part there can be any if El statements inside the else part as well okay so for example we will enter else block only when a is less than equal to 5 okay so we can update the statements inside three to do something thing okay let's look at the code so now if okay first of all I had to change the
            • 75:00 - 75:30 values this should have been equal greater than five greater than 8 is right and this should have been less than five okay so inside else also we can add other conditions all right so if a equal to equal to 5 then print equal to 5 okay now this actually should have been less than or equal to because this has
            • 75:30 - 76:00 both those conditions a can be equal to five or it can be less than it as well uh so now let's try to execute it when the value of a is equal to 5 so now there are four blocks actually inside the third block there's another fourth block which checks for the equality of a with five so now if I have a equal to 5 it will try to it will first of all the
            • 76:00 - 76:30 first condition will fail it will not enter block one then it will check for like obviously like if the first condition fails it will go into the else part okay so it will enter the third block and it will check for the condition over the fourth block and we will try to compare it with five so let's quickly try to run the program it says it first enters the block three which has a statement less than or equal to 5 and then it checks the condition over the block four and it Compares it with five it is again true so it will enter
            • 76:30 - 77:00 the block four as well and it will execute equal to five and then the normal execution happens as it is outside the if and else block so this is how you can add any number of nested if else else if conditions inside it okay so now there is another type of a control statement which is switch okay switch is a a keyword so inside this there can be an expression and this expression should not be constant I mean it can be
            • 77:00 - 77:30 constant but then it there would be no purpose of using it so switch a now there is a condition like there are some rules to be followed in switch statements first of all whatever the expression is inside it should either be an integer or a character okay so now over here in this case a is an integer so we are fine with it now whatever the cases are okay now cases also a keyword okay it will try to match with value one if that is true then it will
            • 77:30 - 78:00 try to execute the statements which are inside this block followed by value one if it tries to match all the values it will try to match with value one it will try to match with value two if there are other values it will try to match it with them and then it will execute that particular block only so if you were to build a calculator you can use a character instead of an integer and then then in the values you can have case followed by a character okay this can be a
            • 78:00 - 78:30 plus and then you can have statement like do a plus b or something like that return a plus b or do a plus b and then the break statement over here says ignore whatever is followed by this break means get out of the switch condition okay if there was no break statement it would have tried to match with other values in the future as well like whatever values are followed by value one it will try to match it with them whenever it encounters a break statement it will try to get out of that
            • 78:30 - 79:00 block so this block is switch block it will try to get out of it okay so I'm not writing the code for this but I really want you to pause at this stage and try to implement a calculator you can take in two values A and B and you can also take an operator in the form of a character okay declare a variable C and then if it is addition inside this state stat Ms you can try to update the value of C to A+ B now if this was subtraction you can update the value of C to a minus B and so on and then after
            • 79:00 - 79:30 this switch block just print the value of C okay this will be your first mini project of A Sort where you try to implement a calculator okay now let's take a look at the rules because switch is a very tricky conditional provision in C++ the case value must be either integer or director there are any number of cases there can be any number of cases okay so this is a case this is another case there can be any number of cases no
            • 79:30 - 80:00 duplicate case values are allowed okay for example if I had value 1 equal to let's say plus sign I cannot have the same like value two cannot or value two value three four five any number of values are there after one it cannot have the same value associated with it okay each statement of case can have a break statement it is optional if we don't have a break statement then it will try to continue comparing it with value two until it matches that
            • 80:00 - 80:30 particular value goes inside that block and there is a break value again okay if there is a break value it will get rid of it otherwise it will keep entering the other values Now default statement is also optional what does the default statement do let's say plus minus divide and multiply we have added the case statements for each of them okay case values have been added for each of them now if someone adds some jargon okay like at the rate sign okay that is very much possible in whenever you're taking
            • 80:30 - 81:00 an input as a operator whenever you are taking the input from a user they can behave in any unexpected way you wanted them to use it as a calculator but they just wanted to mess with you okay so they can add in any character it can be q w any character at all so they can be put into the default statement and you can just print hey can you please add only one of these particular operators plus minus multiply divide or modulo if you want to okay and those statements can be a part of the default so if any
            • 81:00 - 81:30 of the above case values are not true if any of the above case blocks are not entered then it will enter the default block if it is present if it is not present it will just get out of the switch block and nothing will get executed but if the default statement is there then it will enter the default statement whatsoever it is and then it will get rid of it ultimately so these are some of the rules of switch conditional provision by C++ like switch statement has all of
            • 81:30 - 82:00 these provisions and you need to be very mindful of these rules because an addition of a break statement a misinterpretation okay let's say you forgot to write a break where you actually had to so it will try to keep on continuing the execution and comparing it with value two value three value 4 and so on so make sure wherever break needs to be added you need to add a break wherever you actually want break to not exist it is completely fine okay inside a case block there can be if and else condition if you want to there can
            • 82:00 - 82:30 be a nested switch condition as well that's completely fine as well so it is just a piece of code like inside the case value statement it's just a piece of code it can have anything and everything so I feel we are at a good place to take a break for this module one what did we cover we covered a lot of things like we talked about data types okay we talked about data types we talked about C++ as a programming language we talked about programming we talked about
            • 82:30 - 83:00 variables we talked about operators and now we are closing on the conditional statements so now what I would want you to is revise all of these things that we learned in this first module and then we will meet next time in another module where we'll continue with other things about C++ which is there are different types of Loops for Loop while loop do
            • 83:00 - 83:30 while loop and so on then there are functions then there are arrays strings and we also have uh you know pointers and all of those things so I don't want to overwhelm you with what all we are going to cover in the next module but I really want you to have a recap of all of these topics and try to implement it on your own so if you found this content insightful do give it a thumbs up and add in the comments if you have any doubts and if you want to keep receiving
            • 83:30 - 84:00 such insightful content don't forget to subscribe to scalers YouTube channel and don't forget to hit the Bell icon so you never miss out on such important notifications see you in the next module