Explain pointer to the constant and constant pointer? Explain difference between them. What is the use of SendMessage() and PostMessage()? What is the difference between them?
If you have a value which you don’t want to modify or let anyone else to modify then you make that value as constant. It also means that you don’t want to allow the value to be changed or if you have a pointer and you don't want it to be pointed to a different value, you should make it a constant with the const keyword.
Pointer to constant: If a pointer points to constant it is called as pointer to constant. In this case we cannot change the content of constant.
const char *myptr.
declares a pointer to a constant character. You cannot use this pointer to change the value being pointed to:
char a = 'A';
const char *myptr = &a;
*myptr = 'J'; // error - can't change value of *myPtr
constant pointer: Declaring a pointer as constant allows us to change the contents of memory pointed by pointer. But we cannot change the pointer address .
char *const myptr
declares a constant pointer to a character. The location stored in the pointer cannot change but the value can be changed.
What is the use of SendMessage() and PostMessage()? What is the difference between them?
SendMessage() is a function which calls a procedure or a system call for a specified window and it doesn’t return back to the class until the window procedure has processed the message.
PostMessage() is a function which sends a message in the message queue which is associated with the thread and then returns to the class without waiting for the thread to process that message.
The main difference between both of them is mentioned in their definition also which lies in the API calls and the way they return the control to the calling application.
SendMessage() in this function control is not returned to the calling application until the window has processed the message which was sent whereas in PostMessage() the control is returned to the calling application immediately, without considering the success of the message processed.
PostMessage is a Asynchronous function where as SendMessage is a synchronous function.