C++(tutorial – 2) | datatypes and user input operator ||

 Programming codester 

C++(tutorial – 2) | datatypes and user input operator 


So, guys in the previous tutorial we learn about fundamentals, application, uses and structure of c++. 

#questionoftheday

c programming related question:

how the 3rd element in array accessed based on pointer?

A.*a+3 B.*(a+3) C.*(*a+3) D.&(a+3)

Now we will learn about user input operator in object-oriented programming with c++ and data types with c++ 

So, in the previous lecture we studied about output operator and also learnt how to write hello world program with c++! 

Let's see the overview of cout user output operator!! 

In c we use printf for any output statements, that’s like we use cout in object-oriented programming with c++. 

  • cout Syntax. The syntax of the cout object is: cout << var_name; ... 

  • cout with Insertion Operator. The "c" in cout refers to "character" and "out" means "output". … 

Now let's begin our new tutorial!! 

In c we use scanf function to input any data that's like we will use cin to use input any data in object-oriented programming with c++. 

Syntax of cin 
The c++ cin statement is an instance of the class iostream and is used to read data from a standard input device, which is usually a keyboard. For reading inputs, the extraction operator(>>) is combined with the object cin. 

cin is the standard input stream. Usually the stuff someone types in with a keyboard. We can extract values of this stream, using the >> operator. So cin >> n; reads an integer. However, the result of (cin >> variable) is a reference to cin 

cin is a predefined variable that reads data from the keyboard with the extraction operator 

Example of cin ! 

#include<iostream> 

Using namespace std; 

Int main() 

 

int x;  
cout << "Type a number: "; // Type a number and press enter 
cin >> x; // Get user input from the keyboard 
cout << "Your number is: " << x; // Display the input value 

} 

 

 

Explanation: - 

In, Line:1 = header file 

     Line:2 = using namespace std; 

     Line: 3= int main () function 

     Line: 4 = open brace 

     Line: 5 = variable declaration with data type int 

     Line: 6 =user output operator cout  

     Line: 7 = inputting data by user through the cin 

     Line: 8 = output the result 

     Line: 9 = return the value 

     Line: 10 = close brace} 

OUTPUT of the program will be: 

Type a number:  
Your number is: 32 

Full detailed video here: cin explanation 

Now let's see various data types with object-oriented programming with c++: 

 

The data type specifies the size and type of information the variable will store: 

Data Type 

Size 

Description 

boolean 

1 byte 

Stores true or false values 

char 

1 byte 

Stores a single character/letter/number, or ASCII values 

int 

2 or 4 bytes 

Stores whole numbers, without decimals 

float 

4 bytes 

Stores fractional numbers, containing one or more decimals. Sufficient for storing 6-7 decimal digits 

double 

8 bytes 

Stores fractional numbers, containing one or more decimals. Sufficient for storing 15 decimal digits 

 

So, Guys I hope you understood basic data types  and user input concepts of c++. 

Related this topic video link here: 

I also uploaded basic program “Hello world” with c++ in my YouTube channel! 

I mentioned here! Check it out!! 

C tutorials: 

Thank you for your support! 

Learn and explore! 

 

 

 

 

 

 

 

 

Comments

Popular posts from this blog

C programming | Printf and scanf ||

C programming | structure | Fundamentals of Structure

C programming | Fundamentals & Basic information

Basic question related programming || c programming || embedded programming

C++ || Operators with c++

C++ || string with c++ || Part - 1

Compiler & Interpreter | difference and explanation

c++|operators with c++|variables||

C programming | Nested structure | Array, function and pointer of structure|| structure Part-II

C++(oop)| Fundamentals | Concepts||