array in C++ inside forloop -


what happening when write array[i] = '\0' inside loop?

char arraypin[256];  for(int = 0; i<256; i++)  {      arraypin[i] = '\0';  } 

the program attempts access memory @ location of <base address of 'array'> + (<sizeof array element> * 'i') , assign value 0 (binary 0, not character '0'). operation may or may not succeed, , may crash application, depending upon state of 'array' , 'i'.

if array of type char* or char[] , assignment operation succeeds, inserting binary 0 @ position 'i' truncate string @ position when used things understand c-style strings (printf() being 1 example).

so if in for loop across entire length of string, wipe out existing data in string , cause interpreted empty/zero-length string things process c-style strings.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -