I am using the Dev-C ++ compiler. This program is supposed to print 30, but print it 384.
30
384
#include <stdio.h> int main() { int n = 3; int ans; ans = n<<3 + n<<1; printf("%d", ans); getch(); return 0; }
The problem is that the operator +has a higher priority than the operator <<. In fact, you wrote:
+
<<
ans = n << (3 + n) << 1;
Actually you want:
ans = (n<<3) + (n<<1);
Source: https://habr.com/ru/post/1544757/More articles:Incorrect linear interpolation with large x values using Math.Net Numerics - c #Cascade delete does not work if Cascade.persist and Cascade.remove are used together in the parent Entity in Hibernet - hibernateHow to set wait time in JPA EntityManager request - javaShow nice json on html div..possible? - jsonGlTexImage3D exception - c ++How to make my NPM package package "npm WARN prefers global" when installing locally - node.jsWhy doesn't this static bool need to be initialized? - initializationConstruct Eigen :: Convert from Eigen :: Translation - c ++Android installing apk on device gives [SEGMENTATION FAULT] - androidChecking for a date between a date range - javascriptAll Articles