Skip to main content
Filter by
Sorted by
Tagged with
27347 votes
25 answers
1.9m views

Why is processing a sorted array faster than processing an unsorted array?

In this C++ code, sorting the data (before the timed region) makes the primary loop ~6x faster: #include <algorithm> #include <ctime> #include <iostream> int main() { // ...
GManNickG's user avatar
  • 502k
10180 votes
26 answers
1.0m views

What is the '-->' operator in C/C++?

After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated, I was completely surprised that the following snippet compiled and worked in both Visual Studio 2008 and G++ 4.4. ...
4228 votes
1 answer
3.2m views

The Definitive C++ Book Guide and List

This question attempts to collect the few pearls among the dozens of bad C++ books that are published every year. Unlike many other programming languages, which are often picked up on the go from ...
3929 votes
44 answers
1.3m views

What are the differences between a pointer variable and a reference variable?

What is the difference between a pointer variable and a reference variable?
prakash's user avatar
  • 59.6k
3710 votes
11 answers
1.2m views

What does the explicit keyword mean?

What does the explicit keyword mean in C++?
Skizz's user avatar
  • 70.8k
3424 votes
41 answers
1.3m views

What's the problem with "using namespace std;"?

I have heard using namespace std; is wrong, and that I should use std::cout and std::cin directly instead. Why is this? Does it risk declaring variables that share the same name as something in the ...
akbiggs's user avatar
  • 35k
3370 votes
84 answers
2.4m views

How do I iterate over the words of a string?

How do I iterate over the words of a string composed of words separated by whitespace? Note that I'm not interested in C string functions or that kind of character manipulation/access. I prefer ...
3160 votes
27 answers
1.7m views

How to set, clear, and toggle a single bit

How can I set, clear, and toggle a bit?
JeffV's user avatar
  • 54.3k
3149 votes
12 answers
796k views

When should static_cast, dynamic_cast, const_cast, and reinterpret_cast be used?

What are the proper uses of: static_cast dynamic_cast const_cast reinterpret_cast (type)value (C-style cast) type(value) (function-style cast) How does one decide which to use in which specific ...
e.James's user avatar
  • 119k
3122 votes
30 answers
926k views

What is the difference between #include <filename> and #include "filename"?

What is the difference between using angle brackets and quotes in an include directive? #include <filename> #include "filename"
quest49's user avatar
  • 50.7k
2544 votes
8 answers
390k views

What is The Rule of Three?

What does copying an object mean? What are the copy constructor and the copy assignment operator? When do I need to declare them myself? How can I prevent my objects from being copied?
fredoverflow's user avatar
2475 votes
10 answers
1.0m views

What are the basic rules and idioms for operator overloading?

Note: This question and the original answers are from 2010 and partially outdated. Most of it is still good and helpful, but the original text no longer covers everything there is to know about C++ ...
sbi's user avatar
  • 223k
2445 votes
11 answers
260k views

Why are elementwise additions much faster in separate loops than in a combined loop?

Suppose a1, b1, c1, and d1 point to heap memory, and my numerical code has the following core loop. const int n = 100000; for (int j = 0; j < n; j++) { a1[j] += b1[j]; c1[j] += d1[j]; } ...
Johannes Gerer's user avatar
2404 votes
5 answers
513k views

What is the copy-and-swap idiom?

What is the copy-and-swap idiom and when should it be used? What problems does it solve? Does it change for C++11? Related: What are your favorite C++ Coding Style idioms: Copy-swap Copy constructor ...
GManNickG's user avatar
  • 502k
2309 votes
19 answers
815k views

Why can templates only be implemented in the header file?

Quote from The C++ standard library: a tutorial and handbook: The only portable way of using templates at the moment is to implement them in header files by using inline functions. Why is this? (...
MainID's user avatar
  • 29.9k

15 30 50 per page
1
2 3 4 5
54093