位移运算符"<<"与算术运算符"+"的优先级问题

一个优先级问题查了一个上午,主要是位移运算符"<<"与算术运算符"+"搞混了

 

 

 

 #include <iostream>                      
 #include <vector>                        
 #include <string>                        
 //#include <time.h>                      
 #include <ctime>                         
                                          
 using namespace std;                     
 int main(int argc, const char *argv[])   
 {                                        
         //error                          
                                          
         {                                
         cout << " error " << endl;       
         int n = 225478832;               
         //int64_t n = 225478832;         
         int64_t tmp64 = 0;               
         tmp64 = n << 32 + 168027998;     
         cout << tmp64;                   
                                          
         cout << endl;                    
                                          
         int64_t n64 = 225478832;         
         int64_t tmp642 = 0;              
         tmp642 = n64 << 32 + 168027998;  
         cout << tmp642;                  
         cout << endl;                    
         }                                
                                          
                                          
                                          
                                        
      {                                 
      cout <<"right " << endl;          
      int n = 225478832;                
      //int64_t n = 225478832;          
      int64_t tmp64 = 0;                
      tmp64 = (n << 32 )+ 168027998;    
      cout << tmp64;                    
                                        
      cout << endl;                     
                                        
      int64_t n64 = 225478832;          
      int64_t tmp642 = 0;               
      tmp642 = (n64 << 32 )+ 168027998; 
      cout << tmp642;                   
      cout << endl;                     
      }                                 

return 0;
}

//output
/*
 error 
0
0
right 
393506830
968424209548306270
*/

 

posted on 2013-01-15 15:18  Orz..  阅读(563)  评论(0)    收藏  举报

导航