C/C & common Doubts
Expert: Joydeep Bhattacharya - 11/2/2006
QuestionHi
can u plz hep me to clarify foll. questions:
1)What is use of NULL pointer otherthan that error checking and to avoid memory corruptions?
2)What Arithemetic operations cant be done on pointers?
3)What is the use of function pointer other than calling functions with the addresses?
4)Hw to read the binary file?
5)what is generic pointer?
6)after using memmove the src file memory will be erased automatically?
7)What is the diff b/w linux and solaris
8)What is the volatile keyword ? usage?
Thanks in advance
Rgds
Gayatri
AnswerHi Gayatri
Ans 1: null pointer is distinguishable from all other pointer values and which is guaranteed to compare unequal to a pointer to any object or function. That is, a null pointer points definitively nowhere; it is not the address of any object or function. The address-of operator & will never yield a null pointer, nor will a successful call to malloc. This is where a null pointer plays a vital role
Ans 2: All types of pointer arithmetic can be done on pointers but operations like multiplication, division etc can prove costly since you never know where it will point after the operation.
Ans 3: function pointers are basically needed to call function that doesn't have a name like ROM-BIOS or DOS functions that doesn't have a name the function is looked up from the Interrupt Vector Table and the address is loaded to the function pointer and is invoked using that function pointer.
Ans 4: this link explains all about reading and witting a binary file
http://www.metalshell.com/view/source/27/
Ans 5: When a variable is declared as being a pointer to type void it is known as a generic pointer. Since you cannot have a variable of type void, the pointer will not point to any data and therefore cannot be dereferenced. It is still a pointer though, to use it you just have to typecast it to another kind of pointer first. Hence the term Generic pointer.
Ans 6: I think yes since the pointer also get reassigned to the new location ...
Ans 7: Not related to my area
Ans 8: A variable should be declared volatile whenever its value can be changed by something beyond the control of the program in which it appears, such as a concurrently executing thread.
Please feel free to get back to me if you have any more question ....
regards
Joydeep Bhattacharya