Linked Questions

142 votes
9 answers
125k views

Consider: int testfunc1 (const int a) { return a; } int testfunc2 (int const a) { return a; } Are these two functions the same in every aspect or is there a difference? I'm interested in an ...
Nils Pipenbrinck's user avatar
112 votes
9 answers
31k views

In many programs, a #define serves the same purpose as a constant. For example. #define FIELD_WIDTH 10 const int fieldWidth = 10; I commonly see the first form preferred over the other, relying on ...
C. Ross's user avatar
  • 31.9k
92 votes
6 answers
126k views

I want to create a constant static array to be used throughout my Objective-C implementation file, similar to something like this at the top level of my ".m" file: static const int NUM_TYPES ...
Sam's user avatar
  • 2,630
49 votes
10 answers
8k views

In C, shall I prefer constants over defines? I've reading a lot of code lately, and all of the examples make heavy use of defines.
helpermethod's user avatar
  • 62.8k
7 votes
7 answers
15k views

I've been told that if I'm coding in ANSI C to declare in the order that the variables will be used, assert that pointers are not null and that indices are within bounds, and to initialize just before ...
Ande Turner's user avatar
  • 7,202
17 votes
4 answers
11k views

This used to work some weeks ago: template <typename T, T t> T tfunc() { return t + 10; } template <typename T> constexpr T func(T t) { return tfunc<T, t>()...
Gravemind's user avatar
  • 191
3 votes
5 answers
2k views

I'm having difficulties in understanding why C++ behaves in a more "relaxed" way than C when it comes to interpreting and creating types for the parameters of a function. C does the simplest thing in ...
user2485710's user avatar
  • 9,891
7 votes
5 answers
393 views

I was asked how can a value of a const variable can be changed. My my obvious answer was "pointers!" but I tried the next piece of code and I'm puzzled... int main() { const int x = 5; int *...
Avi Shukron's user avatar
  • 6,138
0 votes
3 answers
4k views

Hope you all doing great! Here is what I'm trying to do - I would like to create a program which will save a string with up to 50 symbols (or less) to an array and then print out each array symbol. ...
Den's user avatar
  • 73
11 votes
2 answers
156 views

While this compiles: char* p2c; const char* p2cc = p2c; //fine because lhs pointed type has all the qualifiers of rhs pointed type, this does not: char** p2p2c; const char** p2p2cc = p2p2c; //fail ...
emesx's user avatar
  • 12.8k
2 votes
1 answer
791 views

The following is the method signature in a class. virtual void evaluate(const double *var, double *obj, double *constr) const = 0; virtual void evaluate(unsigned int numPoints, const double **var, ...
Santosh Tiwari's user avatar
6 votes
3 answers
827 views

Take e.g. execve(2), which according to posix has this prototype [1]: int execve(const char *path, char *const argv[], char *const envp[]); To me, it seems as if int execve(const char *path, const ...
Peter Rosin's user avatar