Address Operator (& - Ampersand): Returns address of the given variable. Consider the following example, int *ptr, var = 10; ptr = &var; ptr = &var sets the address of the variable var to pointer ptr. & is also called as reference operator. Let us try to understand the purpose of reference operator using the following example program. #include <stdio.h> int main() { int var = 10, *ptr; /* assigning address of variable var to pointer ptr */ ptr = &var; /* printing the address of the variable var */ printf("Address of var is 0x%x\n", &var); /* printing the value of pointer ptr */ printf("Value of ptr is 0x%x\n", ptr); return 0; } Output: jp@jp-VirtualBox:~/$ ./a.out Address of var is 0xbfdf202c Value of ptr is 0xbfdf202c Indirection Operator('*' - asterisk): The dereference operator is an unary operator which returns the value of
kbhit in c: kbhit function is used to determine if a key has been pressed or not. To use kbhit function in your program you should include the header file "conio.h". If a key has been pressed then it returns a non zero value otherwise returns zero. Declaration : int kbhit(); C programming code for kbhit #include <stdio.h> #include <conio.h> main() { while (!kbhit()) printf("You haven't pressed a key.\n"); return 0; } As long as in the above program user doesn't presses a key kbhit() return zero and (!0) i.e. 1 the condition in while loop is true and "You haven't pressed a key." will be printed again and again. As a key is pressed from the keyboard the condition in while loop become false as now kbhit() will return a non-zero value and ( !(non-zero) = 0), so the control will come out of the while loop.
Comments
Post a Comment