Monday, December 8, 2008

c

Data types and storage classes:A storage class is an attribute that changes the behavior of a variable. It controls the lifetime, scope and linkage.There are five types of storage classes1) auto2) static3) extern4) register5) typedef

calloc vs malloc:-1. calloc gives continous memory chunk..but where as malloc doesnt2. calloc initialises zero to all the memory allocated..but where as malloc leaves the garbage values.3. calloc internally calls malloc,for the implementation.4. calloc is slower in comparison to malloc

a program to interchange 2 variables without using the third one.a=7;b=2;a = a + b;b = a - b;a = a - b;

* The volatile modifier is a directive to the compilers optimizer that operations involving this variable should not be optimized in certain ways.
* The register modifier hints to the compiler that the variable will be heavily used and should be kept in the CPUs registers, if possible, so that it can be accessed faster.
* What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

The strcpy() function is designed to work exclusively with strings. It copies each byte of the source string to the destination string and stops when the terminating null character () has been moved. On the other hand, the memcpy() function is designed to work with any type of data. Because not all data ends with a null character, you must provide the memcpy() function with the number of bytes you want to copy from the source to the destination.

*Why n++ executes faster than n+1?
The expression n++ requires a single machine instruction such as INR to carry out the increment operation whereas, n+1 requires more instructions to carry out this operation.
*How many levels of pointers can you have?The answer depends on what you mean by levels of pointers. If you mean How many levels of indirection can you have in a single declaration? the answer is At least 12

No comments: