Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q. In the C++ programming language, a variable name must start with a letter or

ID: 3175019 • Letter: Q

Question

Q. In the C++ programming language, a variable name must start with a letter or the underscore character ( -), and succeeding characters must be letters, digits, or the underscore character. Uppercase and lowercase letters are considered to be dierent characters.
(a) How many variable names with exactly ve characters can be formed in C++?

(b) How many are there with at most ve characters?

(c) How many are there with at most ve characters, if they must read exactly the same forwards and backwards? For example, kayak and T55T are admissible, but Kayak is not.

Explanation / Answer

(A)

The first letter of a variable name must be any letter (uppercase or lowercase) or underscore. This means there are total 26+26+1 = 53 possible ways to select the first character.

Remaining 4 characters can be anything among an underscore, 10 digits or 52 alphabets i.e. 63 characters. This can be done in 63^4 ways

Hence total possible 5 character variable names are 53 * 63^4 =

(B)

Number of variable names with atmost 5 characters are

53 * 63^4 + 53 * 63^3 + 53 * 63^2 + 53 * 63^1 + 53 =

848373173

(C)

These are called as paliandromes.

Possible 1 letter paliandromes are 53

Possible 2 letter paliandromes are 53

Possible 3 letter paliandromes are 53*63

Possible 4 letter paliandromes are 53*63

Possible 5 letter paliandromes are 53*63*63

Hence total number of possible paliandrome variable names with at most 5 characters are

53 + 53 + 53*63 + 53*63 + 53*63*63 = 217141

834906933