I have two questions:
If we want to declare one million variable names all having the same length then what should be the smallest length possible to use?
If we want to declare one million variable names of any possible valid length then what is the maximum size of the variable name required?
The first character in an identifier must be a-z
, A-Z
, or underscore, for 53 possibilities. Subsequent characters can be digits 0-9
too, for 63 possibilities.
So n
characters give 53 * (63**(n-1)) legal identifiers:
Length Names
1 53
2 3339
3 210357 // much less than 1000000
4 13252491 // much more than 1000000
Some of these are reserved words (int
, return
etc.), which we are not allowed to use. Others begin with an underscore, which the C++ standard frowns on. But these small considerations don't change the answer, which is 4 (to both your questions).