1024programmer Blog C++ Basic Series–Variables: Integer and Floating Point_Who Month’s Blog

C++ Basic Series–Variables: Integer and Floating Point_Who Month’s Blog

class=”markdown_views prism-atom-one-light”>

Write the code as follows

#include
 using namespace std;
 int main()
 {
     
 int a; //integer type 
 a=1; //Assign
 cout<<"This is a:"<<  a<<endl; //output statement
 	
 float b; //floating point 
 b=2.3; //Assign
 cout<<"This is b:"<<  b<<endl;
 	
 float c,d;
 c=a/2; // divide a by 2, assign to c 
 cout<<"This is c:"<<  c<<endl;
 d=b/2; // divide b by 2, assign it to d
 cout<<"This is d:"<<  d<<endl;
 return 0;
 }
 

Analysis

Pay attention to the output results of the floating-point variables c and d. Because a is an integer variable, the result of a/2 is 0, and the decimal part is removed. Only keep the integer part (not Rounding);
and b is a floating-point variable, the result of b/2 is 1.15, and the decimal part is preserved.

Output

output
[This series is only a very basic introduction, suitable for readers who do not need to understand deeply , thank you for reading~]

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/c-basic-series-variables-integer-and-floating-point_who-months-blog/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索