Saturday 12 November 2011

Implicit Casting of Variables in C programming

Implicit Casting of Variables

The C language will in some cases implicitly cast variables of one type into another. Sometimes this is a good
thing (it saves the programmer from having to perform this task), but it can have unintended behavior.
Perhaps the worst implicit cast is that of pointer-to-integer.

void sort( int ar[] , int size )
{
/* code to sort goes here */
}
int main()
{
int array[ 10 ];
sort( 10 , array );
}

Again, this code is clearly not what the programmer intended. The results of actually executing this code,
although undefined, will almost surely be catastrophic.

No comments:

Post a Comment