All Questions

406
votes
5answers
107810 views

How do I use arrays in C++?

C++ inherited arrays from C where they are used virtually everywhere. C++ provides abstractions that are easier to use and less error-prone (std::vector<T> since C++98 and std::array<T, n>...
2267
votes
29answers
696025 views

What are the differences between a pointer variable and a reference variable in C++?

I know references are syntactic sugar, so code is easier to read and write. But what are the differences? Summary from answers and links below: A pointer can be re-assigned any number of times w...
239
votes
7answers
30148 views

What is array decaying?

What is decaying of an array? Is there any relation to array pointers?
220
votes
15answers
250243 views

How to find the 'sizeof' (a pointer pointing to an array)?

First off, here is some code: int main() { int days[] = {1,2,3,4,5}; int *ptr = days; printf("%u\n", sizeof(days)); printf("%u\n", sizeof(ptr)); return 0; } Is there a way to ...
1320
votes
15answers
73342 views

With arrays, why is it the case that a[5] == 5[a]?

As Joel points out in Stack Overflow podcast #34, in C Programming Language (aka: K & R), there is mention of this property of arrays in C: a[5] == 5[a] Joel says that it's because of pointer ari...
142
votes
10answers
41314 views

Is an array name a pointer?

Is an array's name a pointer in C? If not, what is the difference between an array's name and a pointer variable?
1239
votes
12answers
359181 views

What is a smart pointer and when should I use one?

What is a smart pointer and when should I use one?
1787
votes
6answers
391049 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 C-style cast (type)value Function-style cast type(value) How does one decide which to use in which specific cases?...
40
votes
9answers
24516 views

How to access a local variable from a different function using pointers?

May I have any access to a local variable in a different function? If so, how? void replaceNumberAndPrint(int array[3]) { printf("%i\n", array[1]); printf("%i\n", array[1]); } int * getArray...
838
votes
12answers
296146 views

What is the difference between const int*, const int * const, and int const *?

I always mess up how to use const int*, const int * const, and int const * correctly. Is there a set of rules defining what you can and cannot do? I want to know all the do's and all don'ts in terms ...

Previous Next