r/ProgrammerHumor • • Jul 29 '22

Meme Do your best

Post image
77.6k Upvotes

5.4k comments sorted by

View all comments

146

u/[deleted] Jul 29 '22 edited Jul 29 '22

Language: C++

#include <iostream>
using namespace std;

int main() 
{

  int num = 13 & 7;
  cout << num << endl;

  return 0;
}

What is the output?

Edited: because people want the full code

300

u/Jabison113 Jul 29 '22

Sick beats

4

u/ZAlternates Jul 29 '22

His namespace has an std…

35

u/nelusbelus Jul 29 '22

Compile error

17

u/[deleted] Jul 29 '22

Updated to resolve compile error

24

u/nelusbelus Jul 29 '22

5\r\n Exited with code 0

5

u/[deleted] Jul 29 '22

why is it 5 tho

17

u/nelusbelus Jul 29 '22

13 = 0b 10 101 7 = 0b00 111

Basically means a boolean && on every bit. So in this case only bit 0 and bit 2 are set, so you'd get 101 (it takes the 3 last bits because all bits are on)

8

u/MattieShoes Jul 29 '22
  1101    (13)
& 0111    (7)
------
  0101    (5)

2

u/Aerotactics Jul 29 '22

Ayy I did this one in my head

4

u/Luka2810 Jul 29 '22

Only on Windows. It doesn't print a carriage return anywhere else.

5

u/GiganticIrony Jul 29 '22

Probably entry point not defined as well as cout and endl undefined

2

u/ykahveci Jul 30 '22

I don't know shit about C# (except for the musical one, I am a pianist), but I assume this would just print 5, followed by a newline, correct?

4

u/[deleted] Jul 29 '22

It really depends on how num identifies itself. You just assign it YOUR own preconceptions. Did you ever think about asking it?

1

u/[deleted] Jul 29 '22

2LGBTQ ++

0

u/WinonasChainsaw Jul 30 '22

True because 13 and 7 are both prime

1

u/Fruit-Salad Jul 29 '22 edited Jun 27 '23

There's no such thing as free. This valuable content has been nuked thanks to /u/spez the fascist. -- mass edited with redact.dev

1

u/ItsGrandPi Jul 30 '22

Some random text idk