He is the question again, Given the following variables which of the following lines will compile without error? String s = "Hello"; long l = 99; double d = 1.11; int i = 1; int j = 0;
1) j= i << s; 2) j= i << j; 3) j=i << d; 4) j=i << l; The correct answer is 2 & 4.I thought that it was only 2.Can anyone explain why it 4 too?Does'nt it apply arithmetic promtion here?Please help me. Thanks Sangi
[This message has been edited by Jim Yingst (edited June 15, 2000).]
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
posted
0
No, normal aritmetic promotion does not apply to the shift operators. They have their own rules, which are given here: <blockquote>Binary numeric promotion (�5.6.2) is not performed on the operands; rather, unary numeric promotion (�5.6.1) is performed on each operand separately. The type of the shift expression is the promoted type of the left-hand operand.</blockquote>