C++ Primer 学习笔记——表达式

//4.1
#include<iostream>
using std::cout;
int main()
{
    int x = 5 + 10 * 20 / 2;
    double y = 5 + 10 * 20 / 2;
    cout << x << " " << y;
    return 0;
}
//4.10
#include<iostream>
int main()
{
    int num;
    while (std::cin >> num&&num != 42);
    return 0;
}
//4.13
#include<iostream>
int main()
{
    int i ; double b;
    b = i = 3.5;//b=3,i=3
//  i=b = 3.5;//b=3.5,i=3
    std::cout << b << std::endl
        << i;
    return 0;

}
//4.6
#include<iostream>
#include<vector>
using namespace std;

int main()
{
    vector<int> it(0, 10), *iter = &it;
    cout << (*iter).empty();
    //cout << *iter.empty();
    //Error 1   error C2228: left of '.empty' must have class/struct/union  
//点运算符的优先级高于解引用,必须加括号
    return 0;
}
//4.21
#include<iostream>
#include<vector>
using std::vector;
using std::cout;
int main()
{
    vector<int> nint{ 12, 34, 2, 54, 55, 345 };
    for (auto &i : nint)
    {
        if (i % 2 != 0 ? (i = i*i) : i = i)
            cout << i << " ";
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值