586 Answered Questions for the topic C++
05/24/19
The consequences and pros/cons of flushing the stream in c++?
I have recently read an article which stated that using `\ ` is preferable to using `std::endl` because `endl` also flushes the stream. But when I looked for a bit more information on the topic I...
more
C++
05/24/19
What is an unsigned char?
In C/C++, what an `unsigned char` is used for? How is it different from a regular `char`?
C++
05/23/19
Printing 1 to 1000 without loop or conditionals?
**Task**: Print numbers from 1 to 1000 without using any loop or conditional statements. Don't just write the `printf()` or `cout` statement 1000 times.How would you do that using C or C++?
C++
05/22/19
Static linking vs dynamic linking?
Are there any compelling performance reasons to choose static linking over dynamic linking or vice versa in certain situations? I've heard or read the following, but I don't know enough on the...
more
C++
05/21/19
Is there a technical reason to use > (<) instead of != when incrementing by 1 in a 'for' loop?
I almost never see a `for` loop like this: for (int i = 0; 5 != i; ++i) {}Is there a technical reason to use `>` or `<` instead of `!=` when incrementing by 1 in a `for` loop? Or this...
more
C++
05/16/19
How do you reverse a string in place in C or C++?
How do you reverse a string in C or C++ without requiring a separate buffer to hold the reversed string?
C++
05/15/19
How do I list the symbols in a .so file?
How do I list the symbols being exported from a .so file? If possible, I'd also like to know their source (e.g. if they are pulled in from a static library).I'm using gcc 4.0.2, if that makes a...
more
C++
05/13/19
What are C++ access specifiers ?
C++
05/12/19
Is the sizeof(some pointer) always equal to four?
For example:`sizeof(char*)` returns 4. As does `int*`, `long long*`, everything that I've tried. Are there any exceptions to this?
Most efficient/elegant way to clip a number?
Given a real (n), a maximum value this real can be (upper), and a minimum value this real can be (lower), how can we most efficiently clip n, such that it remains between lower and upper?
Of...
more
C++
05/06/19
What are the important topics in C++?
C++
05/06/19
Which is better option to use for dividing an integer number by 2?
Which of the following techniques is the best option for dividing an integer by 2 and why?Technique 1: x = x >> 1;Technique 2: x = x / 2;Here `x` is an integer.
What are the differences between .so and .dylib on osx?
.dylib is the dynamic library extension on OSX, but it's never been clear to me when I can't / shouldn't use a traditional unix .so shared object.Some of the questions I have: - At a conceptual...
more
C++
05/06/19
What's the rationale for null terminated strings?
As much as I love C and C++, I can't help but scratch my head at the choice of null terminated strings:* Length prefixed (i.e. Pascal) strings existed before C* Length prefixed strings make several...
more
C++
05/01/19
unsigned int vs. size_t?
I notice that modern C and C++ code seems to use `size_t` instead of `int`/`unsigned int` pretty much everywhere - from parameters for C string functions to the STL. I am curious as to the reason...
more
C++
04/28/19
Are global variables bad?
In C/C++, are global variables as bad as my professor thinks they are?
C++
04/28/19
What's the purpose of using braces (i.e. {}) for a single-line if or loop?
I'm reading some lecture notes of my C++ lecturer and he wrote the following: > 1. Use Indentation // OK> 2. Never rely on operator precedence - Always use parentheses // OK > 3. Always...
more
C++
04/24/19
return statement vs exit() in main()?
Should I use `exit()` or just `return` statements in `main()`? Personally I favor the `return` statements because I feel it's like reading any other function and the flow control when I'm reading...
more
04/20/19
What is C++ syntax?
What is Linux’s native GUI API?
I hope this doesn’t come across as a stupid question but it’s always something I have wondered. Both Windows (Win32 API) and OS X (Cocoa) have their own APIs to handle windows, events and other OS...
more
C++
03/27/19
Why use apparently meaningless do-while and if-else statements in macros?
In many C/C++ macros I'm seeing the code of the macro wrapped in what seems like a meaningless `do while` loop. Here are examples. #define FOO(X) do { f(X); g(X); } while (0) #define FOO(X)...
more
C++
03/27/19
How do you set, clear, and toggle a single bit?
How do you set, clear, and toggle a bit in C/C++?
C++
03/27/19
How to avoid overflow in expr. A * B - C * D?
I need to compute an expression which looks like:`A*B - C*D`, where their types are: `signed long long int A, B, C, D;`Each number can be really big (not overflowing its type). While `A*B` could...
more
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.