2010-01-10

C++ Associativity

When reading c++ code, find interesting.
If input 0 then num1 is 5 else num1 is input number.

#include

int
main ( )
{
int num1;
std::cin >> num1;
num1 || (num1 = 5);
std::cout << num1 << std::endl;
return 0;
}


If input 0 then num1 is 0 else num1 is always 5.

#include

int
main ( )
{
int num1;
std::cin >> num1;
num1 && (num1 = 5);
std::cout << num1 << std::endl;
return 0;
}

interesting.

0 件のコメント:

BCM4321 on Latitude D430

At kernel 3 find wireless hardware lspci | grep -i wireless  check using current kernel module with PCI bus address lspci -vv -s 0c:...