Well, there's a few conventional names that are used when using common constructs.
i, j, k are the most common indices for for loops (personally, I prefer a, b, c, but that's just me).
accum is used when something needs to be accumulated. For example, to get the sum or the product of a bunch of numbers.
count is used to keep track of how many elements in a container or space match some condition. For example, getting the average of the elements in a vector would use a sum accumulator and a count, although it may not be necessary to actually compute the count.
file, input_file, output_file or variations thereof are commonly used when a function or block of code uses one or two files. It's rare to have more than two files open in the same lexical scope. When that happens, it's usually obvious what to name them.
buffer is used when binary data is read from or written to some kind of virtual or physical I/O device. input_buffer and output_buffer are also common variations.
x, y, z are used to name some variable that moves in one or more dimensions. x is also often used as just a general mathematical variable, as in
1 2 3
|
double square(double x){
return x*x;
}
| |
Of course, there's no general set of rules to name variables because it would have to cover every possible program.
In general, you should name variables based on the semantics of their contents. You shouldn't have to get creative to come up with names. If you have a variable that stores the second degree coefficient for a quadratic equation, you don't name it 'Superman' or 'qwerty'. You name it 'coefficient2', or 'coeff2'. If what the variable does isn't obvious to you, it's because you haven't thought what you're doing all the way through.