C++学习路程 22/3/3 PM 20:00

#include  <iostream>
using namespace std;
#include  <string>// 用string字符串时需要
/*常量定义  #define 宏常量名字  数据  */
#define  Day 7 //Day = 7

int main()
{
    //变量创建   数据类型  变量名 = 变量初始值
    int a = 10;
    cout << "a=" << a << endl;
    cout << "hello world" << endl;
    cout<<"一周多少天:"<<Day<<"天"<<endl;

    //常量定义  const 修饰变量  
    const int month = 12;//定义之后也是常量
    cout<<"A year 有"<<month<<"个月"<<endl;

    short nmu1 = 10;//短整型
    int num2 = 10;//整型
    long num3 = 10;//长整型
    long long num4 = 10;//长长
    // sizeof(数据类型/变量名) 就可得到占用内存为多大
    cout << "占用内存空间是" << sizeof(int) << endl;
    
    /*实型(浮点型、小数)
      单精度 float   7位有效
      双精度 double  15-16位有效*/
    float f1=3.14f;
    double f2=3.14;
    //输出小数时默认位6位有效数字

    //科学计数法
    float f3=3e2;//3 * 10^2
    cout<<"f3= "<<f3<<endl;
    float f4 = 3e-2;//3 * 10^(-2)
    cout << "f4= " << f4 << endl;
    
    //字符型
    char ch = 'a';//只能存一个字符  'abcde'不正确
    cout << "a= " << ch << endl;
    char ch1 = 'abcd';
    cout << "abcd= " << ch1 << endl;//只显示 d
    //字符型变量对应的ASCII编码
    cout << (int)ch << endl;
    // a - 97
    // A - 65

    //转义字符
    //  \n 换行 与 结尾的 <<endl  作用相同
    cout << "\\\n";//  显示一个\需要两个\\来表示
    // \t 水平制表符 == 空格  看着整齐
    cout << "aaa\t hello world "  << endl;
    cout << "aaaaa\t hello world "  << endl;
    cout << "aa\t hello world "  << endl;

    //字符串型
    string name = "姓名";//需要一个头文件,见第三行
    cout << name  << endl;

    //布尔类型 输出0或者1    只要是非0的都代表真
    bool flag = true;//ture=1 真
    cout << flag << endl;
         flag = false;//flase=0 假
    cout << flag << endl;


    // 数据输入  从键盘得到输入
    int a1=0;
    cout<<"赋值操作"<<

    system("pause");
    return 0;
}


//注释  单行//
//     多行/* */
//main()只有一个,源文件中多个函数要调用,则需要命名不同main main1 main2....

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值