cout and cin | first code in C++ | Coding for beginners | Lecture 3


  • Guys whatever we do in our daily life is to benefit us .
  • For example we keep the fruits in mixer to get juice .
  • Here we getting a benefit of converting fruits to juice .
  • Similarly, we are doing coding for some benefits .
  • Similar to mixer we give some inputs to our code/program and get benefits through output .
  • For example we written a code to multiply two numbers then for our given input we get output .If we given 8 and 7 as input we get output as 56 .
  • Here cin will helps us to give input to program/code cout helps us to get the output .Lets study the cin and cout briefly with examples.
  • Execution of cout in c++ with code and examples 
    1. #include<bits/stdc++.h>
    2. using namespace std;
    3. int main()
    4. {
    5.            int lecture_no = 3;
    6.            cout<<"code with dare";
    7.            cout<<endl;
    8.            cout<<lecture_no;
    9.            return 0;
    10. }
  • OUTPUT : 
      • code with dare
      • 3
  • click here to know what is #inlude<bits/stdc++.h>
  • In the above example code with dare is a sentence so it is kept between "" and lecture_no is a variable so it used directly .
  • cout can be used two ways either we an print directly with sentence with quotes or can be printed via variables
  • click here to know what are variables
  • In above code endl used to shift to new line so in output 3 is printed in new line.
  • We can print multiple answer at a time like shown below
    • cout<<"code_with_dare"<<endl<<lecture_no;
    • This above line also give same output
  • Execution of cin in c++ with code and examples 
  • In the first code in line number 5 we initiated lecture_number with 3.Now we an ask user to provide the lecture number using cin.This is the beauty of coding.
    1. #include<bits/stdc++.h>
    2. using namespace std;
    3. int main()
    4. {
    5.            int lecture_no ;
    6.            cin>>lecture_no;
    7.            cout<<lecture_no;
    8.            return 0;
    9. }
  • OUTPUT : 
    • depends upon user input .
  • For the above code whenever we run the program it will ask user to give input and it will store in the variable name lecture_no .This can be done with line number 5 
  • Now ,as known line number 7 prints the number which is stored in lecture_no.
  • Here i provide sample video which helps you in compiling code.Please see it
  • 👀

  • In the above video i compiled the two programs ,In second code it asked me for input and i given 5536262 as input it stored this number in lecture_no and printed 5536262as per line no 7

*****Don't worry if you are confused you will know everything in further concepts ,Don't give up if you are confused . Don't Panic ,be patient we will learn everything*****

***** If you have any doubts please ask in comment box*****



 

Guys if you have any doubts, please let me know

Post a Comment (0)
Previous Post Next Post

How to start Coding | coding for beginners | Lecture 1