c/c++运算符与精度(部分
double,float,字符型,字符串,bool
#include<string> #include<iostream> using namespace std; int main() { double f1 = 31.415926; cout << "f1=" << f1 << endl;//单精度与双精度默认六位有效数字 float d1 = 31.415926f; //float 七位有效,double十五~十六位有效 cout << "d1=" << d1 << endl; //字符型 char a = 12; cout <<(int)a<< endl;//98.强制转换,可以输出数字,但是要强转 //字符串c语言: char s1[] = "nihao shijie "; cout << s1 <<"大小为" <<sizeof(s1)<< endl; //c++版 string s2 = "buhao shijie "; cout << s2 << "大小为" << sizeof(s2) << endl; //BOOL类型: true——真(1) false——假(0),占用一字节。 bool flag = true; bool a = false; cout << "true的值" << flag << endl << "falsed的值" << a << endl; cout<<"wei flag fuzhi"<<endl; cin>>flag; cout<<flag<<endl; //输入cin string a = "nihao"; cout << "请输入字符串" << endl;// 字符串输入遇空格停止,后续不计入 cin >> a; cout << a <<endl<< "daxiao" << endl << sizeof(a) << endl;
四种运算符:
//各种运算符:1,算数运算符: + - * / % ++ -- int a = 6; int b = -2; cout << a/b << endl; cout << -6 % 4 << endl;//求余与第一个数的符号有关,都得整型 cout << a++ <<endl<< a << endl; //2.赋值运算符:+= -= *= /= %= = int a = 8; a %= 6; cout << a << endl; //3.比较运算符 > < == != >= <= //int a = 9; //int v = 2; //cout << (a > v )<< endl; //4.逻辑运算符 ! && || 最短作用
上一篇:
通过多线程提高代码的执行效率例子
下一篇:
IDEA反编译java.class文件