Casting is telling the compiler to use a variable as the specified type indicated in the cast.
All datatypes and user defined types as well boil down to raw memory with no specified datatype, for example: char* buff = new char[1024]; // A dynamically allocated array of chars // We can cast this to void types ( meaning just memory with no specified type) void* ptr = (void*)buff; // We can cast ptr from a void pointer into anything, for example: int *intptr = (int*)ptr; //Now intptr points to an array of integer data In the above code sample we just told the compiler to use the void memory as integer data. So, now if we use the array pointed to by intptr we get this: intptr++; // increments sizeof int number of bytes If we use it as char data we get buff++; // increments sizeof char number of bytes We could cast this memory into anything we want, but if we cast it into some user-defined type larger than 1024 bytes we'll use more memory than we allocated. Hope this helps! --- On Thu, 3/19/09, zeb_zxc <[email protected]> wrote: From: zeb_zxc <[email protected]> Subject: [c-prog] cast To: [email protected] Date: Thursday, March 19, 2009, 7:50 AM it is very difficult to understand the casting(data type conversion)can any body help me in understanding the casting [Non-text portions of this message have been removed]
