49

So... I learnt a couple things today about C++ language which I didn’t know before...

1. float var = 5.9;
std::cout << ( var == 5.9 );

// shows 0 (false) coz of float and double thing... apparently, 5.9 isn’t automatically converted to float when compared to one πŸ€”

2. arr[ i ] == i[ arr ]

Well... I guess I now like my college 1% more from the previous % whatever that was 😊☺️

Comments
  • 3
    Informative, thank you, have some ++ from me 😎
  • 4
    @coolq thanks πŸ€—
  • 25
    If you are wondering why:
    arr[i] is *(arr+i) is *(i+arr) is i[arr]
  • 8
    @ComradeBob
    Ahhh, it makes so much sense!
    Thanks for the explanation πŸ‘

    Why doesn't C++ pick up that 'i' is an integer though? Would have thought an error would have come out of that?
  • 5
    @ComradeBob thanks for telling... I understood that 😊... but I just find it kinda funny...
    M very sure I don’t wanna look at a codebase using something like:
    -2[ arr ];
    It is confusing πŸ˜…πŸ˜…

    Ur comment shall b useful for many people though πŸ€—
  • 4
    We learned all these things last year 😎 (we were literally drilled to know all those things)
  • 2
    @coolq it simply doesn’t matter...
    I believe what happens is that one type can auto change at times to work with another one if the vice verse isn’t possible πŸ€”
  • 2
    @coolq something like how,
    If I write:

    int p = 10 + ‘c’ + 48;

    ‘c’ is auto converted to int to make things work...

    This is how I understand it anyways...

    I also thought first that it wud b an error πŸ˜…
  • 3
    All chars are basically numbers, you can find them in the Ascii table.
    For instance, if you want to turn your char array into all uppercase, write carr[i]+32
  • 2
    @ComradeBob yea that is true... it is just my style of understanding how the compiler understands its semantics πŸ˜…πŸ˜…
    Probably wrong style though... do enlighten with ur take plz πŸ€—
  • 3
    It will do a cast to int, something like static_cast<int>('c') I guess. Might ve a bit different since your 'c' is a const char, but about the idea. Cast = convert, in case you don't know the verb. Helps with stackoverflow searches
  • 2
    @ComradeBob
    @Electrux
    I find this stuff useful because I'm writing my own simple C compiler for my own CPU type, it's a very simple CPU, and this gives me insight as to how a C++ compiler works.

    Thank you πŸ˜‚
  • 2
    @coolq holy cow!!! Do tell me when u have a version done plz 😲😲😎😎
    And good luck with it too...
    Glad I helped with something 😊
  • 2
    @Electrux
    I might post a picture of it when I'm done, it's called a breadboard CPU 😊

    So far I've been making my design in a logic simulator, it's looking promising πŸ˜‚

    Making your own compiler is a problem with having your own architecture. I'm wondering if I could translate another? Perhaps C2BF?

    Thanks for your interest!
  • 2
    @coolq lol I feel like I m doing nothing now... kudos to ur project man ✌🏻🀘🏻☺️☺️
  • 1
    @Autism420 wth just happened... explain plz? πŸ˜…
  • 1
    @Autism420 seems to have something to do with 3 decimal places... can’t seem to understand what though πŸ˜•πŸ€”
  • 1
    @Autism420 nvm the above comment then 🀣🀣
    That’s so cool!!! 😎😎🀘🏻
    Thanks a million πŸ€—πŸ€—πŸ™ŒπŸ»πŸ™ŒπŸ»
  • 1
    @Autism420 just did some reading on it... now I wanna thank u in person πŸ™ŒπŸ»πŸ™ŒπŸ»πŸ˜ŽπŸ˜Ž
    On the other hand I wanna forget programming an reboot πŸ˜‚πŸ˜‚πŸ˜‚
  • 2
    Literally everything falls back down to a point in C
  • 1
    @iSwimInTheC which is? 😲
  • 0
    @Artemix I think I understood some of the words you said. Can you explain it in stupid? If I understand correctly, lvalues cant be const for instance, such as 1 = x; but x = 1; is possible, as x is both l and rvalue and 1 is an rvalue.
  • 0
    @ComradeBob as I read, any value which has a location to store data which can be modified is an lvalue 😌
    Seems to b sufficiently correct till some exception pops up
  • 0
    @Electrux that makes sense, the compiler likely replaces things such as const int with its respective value in the code and doesnt reserve memory
  • 0
    @ComradeBob seems like it πŸ˜…
  • 0
    @ComradeBob although... I do think that it simply checks if the possibly lvalue is actually a const or something in which case it no longer is an lvalue hence the statement wud b incorrect
  • 1
    Everyone is saying "thank you", but if the same thing happened in JavaScript now everyone would complain about how crazy is the language
  • 0
    @crisz maybe because people r used to this type of stuff in Java, but not in C++?
    And well, things do make sense if u try to understand deep enuf (although I hate where C++ is going these days :(
    )
    Maybe they make sense in JS too... idk that language so no comments there πŸ€—
  • 2
    1. Is because the comparison is made between mantissas of different values due to precision differences
  • 1
    That's why you don't compare float values like that... Check if the difference is smaller than some tolerance value.
  • 1
    @Double-A if the absolute value of the difference (not to be picky here)
  • 1
    Float is mostly used with GPU. Default is double. So just put 5.9f if you want the float version.
Add Comment