Most C++ programmers are familiar with the ternary operator:
x = (y < 0) ? 10 : 20;
However, they don't realize that it can be used as an lvalue:
(a == 0 ? a : b) = 1;
which is shorthand for
if (a == 0)
a = 1;
else
b = 1;
Use with caution :-)
Little known features of C/C++, The Hidden Features series is great for people who are new to a certain language. I have collected few of the features of both C and C++ here. Like the ternary Here are some interesting hidden C# features, in the form of undocumented C# keywords: __makeref __reftype __refvalue __arglist These are undocumented C# keywords (even Visual Studio recognizes them!) that were added to for a more efficient boxing/unboxing prior to generics.
You can put URIs into C++ source without error. For example:
void foo() {
http://stackoverflow.com/
int bar = 4;
...
}
Hidden features of C++, Here we will see some good features and tricks of C++ programming language that can help us in different area. Like if we want to participate in The most famous of "hidden" feature of C++ is template metaprogramming, as it enables you to have your program partially (or totally) executed at compile-time instead of runtime. This is difficult, though, and you must have a solid grasp on templates before trying it.
Pointer arithmetics.
C++ programmers prefer to avoid pointers because of the bugs that can be introduced.
The coolest C++ I've ever seen though? Analog literals.
What are some cool hidden features of c++? : cpp, What are some cool hidden features of c++?. Hello,. I saw a post on Stack overflow for Hidden features of languages. I did a bit of digging and couldn't find any Hidden features of C++ C++ Server Side Programming Programming Here we will see some good features and tricks of C++ programming language that can help us in different area. Like if we want to participate in some competitive programming events, then these tricks will help us to reduce the time for writing codes.
[C] Hidden features of C, Some of these are new features added to C in C11, and could be achieved using compiler extensions however they're particularly useful Yes it is risky to use them, these hidden keywords, were introduced before generics to make interop,P/Invoke faster, because these features let you avoid boxing/unboxing value types. – Pop Catalin Sep 15 '08 at 9:47
One language feature that I consider to be somewhat hidden, because I had never heard about it throughout my entire time in school, is the namespace alias. It wasn't brought to my attention until I ran into examples of it in the boost documentation. Of course, now that I know about it you can find it in any standard C++ reference.
namespace fs = boost::filesystem;
fs::path myPath( strPath, fs::native );
C Programming Tips and Tricks Every Programmer Should Know, Or keep a check on some function which is spuriously taking extra execution time than expected? Here is the code snippet implemented using a set of macros to Zoom tips and tricks: 13 hidden features to try. Learn to change your background, your audio and video settings, and how to share your screen. Alison DeNisco Rayome. April 16, 2020 4:00 a.m. PT.
What are some cool C tricks?, Can a program written in a language different from C/C++ still crash? For example if a function fails before the printf then it will print something rather different. * Then there are hidden gems in the standard library, such as qsort(),bsearch(), Got Mercedes? Must watch video for Mercedes-Benz owners, demo 10 hidden features available in most Mercedes models over the past 10 - 20 years, full tutorial and explanation. This video is better
What are some hidden features of C++?, I was going to pass on this question thinking “why would features be hidden?”. Then I remembered that we did hide some feature long ago… The case of the 13 Secret Codes That Unlock Hidden Features on Your Phone. The USSD protocol allows you to access hidden features you didn't know about right from your smartphone's dialer. But there is some
The Hidden Unsafe Features of C - Level Up Coding, The Hidden Unsafe Features of C#. Working with pointers, breaking type safety, and all sorts of fun in the unmanaged world. 23 Hidden Tricks Inside Windows 10. Windows is a vast operating system with plenty of features you might never stumble upon. Make the most of Windows 10 with these expert tips.
Comments @Devtron - I've seen some awesome bugs (i.e. unexpected behavior) sold as features. In fact, the games industry actually tries to make this happen nowadays and calls it "emergent gameplay" (also, check out "TK Surfing" from Psi-Ops, was purely a bug, then they left it as is and its one of the best features of the game IMHO) @Laith J: Not very many people have read the 786-page ISO C++ standard from cover to cover -- but I suppose you have, and you've retained all of it, right? @Laith, @j_random: See my question "What is a programmer's joke, how do I recognize it, and what is the appropriate response" at stackoverflow.com/questions/1/you-have-been-link-rolled. See meta.stackexchange.com/questions/56669/…, meta.stackexchange.com/questions/57226/… and related Meta posts. Very interesting. I can see that making some unreadable code though. Yikes. (a == 0 ? a : b) = (y < 0 ? 10 : 20); (b ? trueCount : falseCount)++ Dunno if it's GCC specific, but I was surprised to find this also worked: (value ? function1 : function2)()
. @Chris Burt-Brown: No, that should work everywhere if they have the same type (i.e. no defaulted arguments) function1
and function2
are implictly converted to function pointers, and the result is implicitly converted back. But only one per function, i suspect? :) @jpoh: http followed by a colon becomes a "label" which you use in a goto statement later. you get that warning from your compiler because it's not used in any goto statement in the above example.