techpreparation-homepage

Home  Interview Questions  Aptitude Questions  Tutorials  Placement Papers  Search  Resume Guide  Soft Skills  Video  Forum  Blog


Technical Interview Questions

.Net Interview Questions
C++ Interview Questions
Unix Interview Questions
                              .........More

Download e-Books
C Interview Questions e-book

Aptitude Interview Questions
C/C++ Aptitude Questions
C Aptitude Questions
                              .........More

Online Quiz
C Online Quiz
C++ Online Quiz
                              .........More

 

 

  

  Home > C Interview Questions >

When should a type cast be used ?

There are two situations in which to use a type cast. The first use is to change the type of an operand to an arithmetic operation so that the operation will be performed properly.

The second case is to cast pointer types to and from void * in order to interface with functions that expect or return void pointers.

For example, the following line type casts the return value of the call to malloc() to be a pointer to a foo structure.

struct foo *p = (struct foo *) malloc(sizeof(struct foo));

 

Have a Question ? post your questions here. It will be answered as soon as possible.