The following code is working fine in C but when I try to write it in c++ then the program does not work.Please explain.
C code :
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a = 33,b = 7;
printf("%d\n",a&b);
return 0;
}
C++ code:
#include<iostream>
using namespace std;
int main()
{
int a = 33,b = 7;
cout << 33&7 << endl;
return 0;
}
Watch your operator precedence:
&has lower precedence than<<. So you need to use().For the full list of operator precedence in C and C++:
http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence