20170626工作日记

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/github_37856429/article/details/73743311

2017年6月26日 周一

C语言中的数据类型

这里写图片描述

C++中新的数据类型

  逻辑类型
C 没提供 非0 0
C++ bool ture false

C语言提供的初始化方法 int x = 1204;

C++提供的两种初始化方法

  • 复制初始化 int x = 1024;
  • 直接初始化 int x (1024);

随用随定义

C语言 所有变量定义必须位于函数体的最前面
C++ 所有变量随用随定义
这里写图片描述

使用cout进行输出

cout << x << endl;
cout << “x + y =”<

使用cin进行输入

cin >> x;
cin >> x >> y;

#include<iostream>
#include<stdlib.h>
using namespace std;

//要求:提示用户输入一个整数,将整数分别以8进制10进制16进制打印在屏幕上
//要求:提示用户输入一个布尔值(0或1),以布尔方式打印在屏幕上
int main(void)
{
    int x = 0;
    cout << "请输入一个整数:" << endl;
    cin >> x;
    cout << oct << x << endl;  //8进制
    cout << dec << x << endl; //10进制
    cout << hex << x << endl; //16进制

    cout << "请输入一个布尔值(0,1) : " << endl;
    bool y = false; //定义y为布尔型
    cin >> y;
    cout << boolalpha << y << endl; //boolalpha将y输出是布尔型
    system("pause");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/github_37856429/article/details/73743311