Setting the size of an Array

Posted: February 7, 2014 in Uncategorized

we need to be very careful while setting the size of an array . Especially, then we use those variables in looping and conditions.

Let us see one example where we are creating a char array and reading the files based on the char array value.

char param[200];
// get input values
while(param.eof())
{
// do some stuff
}

Due to some chage the in param value we have more than 10 fileds to be added in param . even if we are adding 10 entries to param the loop will end up in the infitie execution.

This is because the value in the char arr can store only upto 200 characters. Since we added some more values to param , the size of the param will cross more than 200 . Bcoz of that param.eof will never get matched and our application will be in running in infite loop.

Hence, we need to be careful while allocation memory to a char variable

Advertisements

Comments are closed.