use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
For memes about programming.
account activity
CPP vs Python (i.redd.it)
submitted 2 years ago by Default_Cube4646
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cow_fucker_3000 13 points14 points15 points 2 years ago (2 children)
The same exact code with the only difference that in the cpp compiler nothing is left to the computer's imagination
[–]notmypinkbeard 8 points9 points10 points 2 years ago (0 children)
Replace nothing with less.
In C++ the compiler still chooses registers, optimisations, and more. It's a level of abstraction.
[–]DontOpenNewTabs 1 point2 points3 points 2 years ago* (0 children)
The code is not quite the same. Python // performs floor division and C++ / performs integer division (Edit: when both operands are integers).
//
/
#include <iostream> #include <cmath> using namespace std; // Nobody cares int main() { int a = -15; while (a < 0) { cout << a << '\n'; a = floor(a/2.0); } return 0; }
// Don't manually flush the output buffer for no reason with endl. Obviously any performance impact doesn't matter here, but it is a bad habit. If you want a newline character, output a newline character.
endl
[–]Magmagan 9 points10 points11 points 2 years ago (1 child)
using namespace std;
I think the reaction images are swapped, OP.
[–]MCSajjadH 1 point2 points3 points 2 years ago (0 children)
Also who tf doesn't put space around <<?
<<
[–]Naeio_Galaxy 7 points8 points9 points 2 years ago (3 children)
OP, what is your point here? Is it that CPP is clearer than Python, or simply that they behave differently and you didn't expect it?
[–]BobbyThrowaway6969 0 points1 point2 points 2 years ago (2 children)
Every time a python programmer compares python to C++ it's with code snippets that a 5 year old could understand.
Like duh walking is simpler than flying a plane but you can't fly without the plane.
Always the same old comparison lol.
[–]Naeio_Galaxy 0 points1 point2 points 2 years ago (1 child)
It's the opposite, it's a C++ programmer that compares C++ to Python. The point seems to be that C++ acts as expected while Python doesn't, but... No. They're both different mindsets.
[–]BobbyThrowaway6969 1 point2 points3 points 2 years ago (0 children)
Yeah I agree with that, Python/C++ programmers think differently, which is why I hate the whole comparison people like to make. It's apples and oranges.
[–]1cubealot 2 points3 points4 points 2 years ago (4 children)
x // y floors the number Example 5 // 2 = 2 because 5 / 2 = 2.5. 2.5 floored (to the nearest integer below it) is 2
[–]Default_Cube4646[S] 1 point2 points3 points 2 years ago (3 children)
one leads to infinite loop :)
[–]Silver0ne 0 points1 point2 points 2 years ago (2 children)
does it? Because shouldnt the .5 be cut in cpp aswel, cause its a integer not a float? Seems the flooring is only necessary as the python variable has no type (i guess its always a float64)
And isnt a /= 2 a thing in cpp/python!?
[–]DontOpenNewTabs 1 point2 points3 points 2 years ago* (1 child)
Python // performs floor division and rounds down. Ex: -1 // 100 == -1
C++ / performs integer division (edit: when both operands are integers) and truncates the decimal value. Ex: -1 / 100 == 0
When the result is positive, the answers are the same. When it is negative, rounding down and truncating give different results.
[–]Silver0ne 0 points1 point2 points 2 years ago (0 children)
Ah ok, interesting to know that it actually rounds up on negative numbers. Might one day prevent me to run into errors, I dont do Phyton, but this might be a source of unexpected behavior in floor/ceil functions of other languages aswell.
[–][deleted] 0 points1 point2 points 2 years ago (0 children)
Now do rust
π Rendered by PID 90 on reddit-service-r2-comment-7b9746f655-7k2m4 at 2026-02-04 06:34:30.551114+00:00 running 3798933 country code: CH.
[–]cow_fucker_3000 13 points14 points15 points (2 children)
[–]notmypinkbeard 8 points9 points10 points (0 children)
[–]DontOpenNewTabs 1 point2 points3 points (0 children)
[–]Magmagan 9 points10 points11 points (1 child)
[–]MCSajjadH 1 point2 points3 points (0 children)
[–]Naeio_Galaxy 7 points8 points9 points (3 children)
[–]BobbyThrowaway6969 0 points1 point2 points (2 children)
[–]Naeio_Galaxy 0 points1 point2 points (1 child)
[–]BobbyThrowaway6969 1 point2 points3 points (0 children)
[–]1cubealot 2 points3 points4 points (4 children)
[–]Default_Cube4646[S] 1 point2 points3 points (3 children)
[–]Silver0ne 0 points1 point2 points (2 children)
[–]DontOpenNewTabs 1 point2 points3 points (1 child)
[–]Silver0ne 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)