Given the following in C:
unsigned short x=0xFFFF,y=0xFFFF;
Without checking, assuming LP64. What is the correct format specifier X below and result:
printf( “%X\n”, x*y);
% | result
=========
A. d | -131071
B. u | 4294836225
C. d | UB
D. u | UB
#CPolls
#Programming
-
Prikaži ovu nit
Shafik Yaghmour je proslijedio/a tweet korisnika/ceShafik Yaghmour
I provided the C++ specific answer here: https://twitter.com/shafikyaghmour/status/1223122542413537286 … The answer here is C the result is int and the the multiplication invokes undefined behavior. The major difference in the answer will be the standard being referred to but the conversions and promotions are close.
Shafik Yaghmour je dodan/na,
22:58 - 30. sij 2020.
0 replies
0 proslijeđenih tweetova
1 korisnik označava da mu se sviđa
Čini se da učitavanje traje već neko vrijeme.
Twitter je možda preopterećen ili ima kratkotrajnih poteškoća u radu. Pokušajte ponovno ili potražite dodatne informacije u odjeljku Status Twittera.
The answer is D, this is undefined behavior but how you might protest, unsigned number don’t have undefined behavior on overflow, do they?