Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
retoor120042yLearning C is a rollercoaster. Much higs and lows. The day I delevered a 'big' application without leaks and stable I felt like a god
-
// C/C++
int arr[] = {1,2,3,4,5};
2[arr] = 42;
What will the array be filled with? -
-
@Demolishun
{1,2,42,4,5}
Spoilers below
.
.
.
.
.
.
.
.
.
.
.
.
.
.
For those foreign to pointer arithmetic, in C/C++, array indexing is basically address arithmetic (as in, addition) a[2] is the same as 2[a], meaning address of a plus 2 times the size of a.
Kudos to you. Great brain teasing question for those learning the eldritch mysteries of real languages 🙂 -
@CoreFusionX I honestly didn't know if that for loop would work until I tried it. I figured it could conclude based upon size of array the loop constraints. Keep that in my back pocket. Wouldn't work with dynamic array I don't think.
-
@Demolishun
The iterator notation in c++ works for c arrays (since they are of known size at compile time) and c++ constructs (such as vector) that are aware of iterators.
It won't work on c++ "dynamic" (as in, runtime sized arrays, since those are pointers, not arrays), and there's a non trivial distinction (unless the compiler can constexpr the size, but I digress).
The concept of C variable length arrays is not a thing in C++, so can't really consider those. -
C++ was one of my first languages. And the more you learn about how C++ works, the more you learn to appreciate higher level languages.
I love C++ for teaching me stuff and giving me better understanding of programming, but I hate C++ for actual programming. -
@Lensflare
The way I see it?
Once you know how to drive manual, by all means buy an automatic.
There's a reason you can't buy a manual if you got your license on automatic. -
@Demolishun
In Spain, if you do the exam for your driving license on an automatic transmission car, you can drive AT cars, but not manual ones.
If you do the exam on a MT car, you can drive both. -
@Demolishun As someone that does mainly C programming, i was confused why you ask this, of course it is {1,2,42,4,5}. But then i rember that this doesn't work in other languages.
In C, n[m] is the same as (*((n)+(m))). So if course n[m] is the same as m[n]
Related Rants
Learning C/C++ started to become fun, mainly because I've managed to do seemingly cursed stuff lately.
For example, today, I learned you could totally call a class member function using a type-matching nullptr variable. The 'this' variable is so null that it will crash as soon as the program hits 'this', though, but the control flow does go into the function.
It's not *that* cursed once you learn the behind-the-scene stuff, but that kind of weird s#!+ is funny, even amusing for me, who've mained languages other than C/C++.
rant
c++
c