c++ - Array with characters as key, default value to 0 -


i creating array in c++:

int my_array[100]; 

i want use array my_array[a], my_array[b] ... characters in place of numbers. works well, program make my_array[a]++; my_array[b]++; etc., default value of each element not 0, , don't understand why.

i tried

int my_array[100]={0}; 

but no success, , dont want declare each element my_array[a]=0;myarray[b]=0; ...

how can this?

if c char variable, can c - 'a' transform index of array:

array[c - 'a'] = 0; 

this works because:

'a' - 'a' == 0 'b' - 'a' == 1 'c' - 'a' == 2 etc. 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -