1.若有以下说明语句和定义语句,则下面表达式中值为3的是
#includeusing namespace std; int main() { struct s { int i1; struct s *i2; }; static struct s a[3] = { 1,&a[1],2,&a[2],3,&a[0] }; static struct s *ptr; ptr = &a[1]; //选项A //cout << ptr->i1++ << endl;//2 //选项B //cout << ptr++->i1 << endl;//2 //选项C //cout << *ptr->i1 << endl;//报错,*的操作数必须是指针 //选项D cout << ++ptr->i1 << endl;//3,先->再++ return 0; }
2.输出值为6的是
int main() {
struct st {
int n;
struct st *next;
};
static st a[3] = { 5,&a[1],7,&a[2],9,NULL }, *p;
p = &a[0];
//选项A 先->再++
//cout << p++->n << endl;//5
//cout<n<再++
//cout << p->n++ << endl;//5
//cout<n<n<n << endl;//7
//cout << ++(p->n) << endl;//6,
cout << ++p->n << endl;//6,->优先级高于++
return 0;
}



