第4章 表达式

4.19

int ival, *ptr;  vector<int> vec;

(a):ptr != 0 && *ptr++                    (ptr != 0) && (*ptr++)  判断ptr指针是否为空,若不为空判断,指向的int值是否为0,然后ptr指向下个元素

4.20

(c)非法,解引用运算符的优先级低于点运算符,而iter没有该成员函数;

4.21

int main()
{
    vector <int> v1{1,2,3,4,5,6,7};
    int ji = 0;
    for (auto &i:v1)
    {        
        ji = (i % 2 != 0) ? i * 2 : i;
        cout <<ji<< endl;
    }
}
View Code

4.22

int main()
{
    int grade;
    cout << "Plz input the grade";
    cin >> grade;
    string finalgrade;
    finalgrade = (grade > 90) ? "high pass" : grade > 75 ? "pass" : grade > 60 ? "low pass" : "fail";
    cout << finalgrade;
}
View Code

 

posted @ 2017-12-16 17:34  东风知我欲山行  阅读(109)  评论(0编辑  收藏  举报