Be careful about array size when u are using strcpThis tip submitted by Bhushan Verma on 2005-10-19 03:17:26. It has been viewed 45574 times.
Rating of 5.8 with 206 votes
If we copy or insert data more into an array of limited size, it is referred as array overflow.
Look at the following code:
char var2 = \"bhushan\"; /* '\0' is not added ,as size is given as 7*/
strcpy( var1, var2 );
Here, we can find that var2 (“bhushan”) is not terminated with a Null terminator (‘\0’). So when we copy var2 to var1 using strcpy( ), the strcpy( ) routine will copy all the character to var2 until it finds ‘\0’ in memory. So array overflow may result in memory overwrite!
Help your fellow programmers! Add a tip!