What are the difference between getch(),getche(),getchar()
We have all used getch() at the end of our program in turbo C++ compiler,but its not used/required in the gcc/g++/visual studio compiler..the question is why?
Actually the getch() is an input function which expects a value to be taken as input from the standard input device of a computer i.e., the keyboard.But the fact is it doesnt wait for the pressing of enter button to take the value as input rather as soon as the value is typed it take it as the input and it doesnt throw the input value to the VDU.Until and unless we provide an input the function halts itself at this line and as soon as we give the input the execution of the line completes and that inputted value leavs in the input buffer memory.As turbo C++/C by default dont let the output screen to halt we use this function just to hold the output(definitly if there is any).In the gcc/g++/visual studio compiler they are capable of holding the output data by themself hence we dont need the getch() function here.
getche() function does the same thing as that of getch()..in addition it 'e'choes or send the input value to the VDU.We can also use this function in the turbo C++/C compiler to halt the output screen just that u will see the input key u pressed for a fraction of second before the screen goes away.
getchar() on the other hand takes the input and wait for the enter key to be hit before it can take the pressed key value as the input unlike the previous two.Hence it's very easy to see what is being given as input as the pressed key is echoed to the VDU screen as long as the enter key is not hit..and definitly also after that.
Saturday, November 7, 2009
Pointers
It is said that if a C programmer never have any problem in pointer then he is a hoax.Its confusing problematic and sometimes make ur head to go in tizzy.I will discuss here some of the not usual terms of pointers.
Dangling Pointer
Though most of us know this thing but few has a clear idea about this thing.But the most amusing thing is that we every body have used and is using this pointer unknowingly(except the most professionals one..who,I'm sure have done so previously in their life).
Dangling pointer is referred to that pointer which are pointing to a particular memory adress which has been already dereferenced already i.e., the object has been deleted without modifying the value of the pointer pointing its adress which still refers to the memory location of the dereferenced memory.
Now as the program continues it may refer that particular memory to new variables while the previous(now dangling) pointer is still referencing the memory..which might call for unpredictable behaviour.
An example of dangling pointer is when we make an array/block of memory using malloc/calloc.As soon as our function is over we call free() function to free it...but the pointer variable stays as the dangling pointer.
int main()
{
int *p;
p = (int *) malloc(sizeof(int));
/* ..... program steps .... */
free(p) ; // the pointer variable p becomes dangling
p=NULL; // the pointer variable is no longer dangling
}
Another dangling pointer example ----
int *f1(void)
{
int num = 10;
/* ...... program steps .....*/
return #
}
The above function returns the address value of the stack allocated localy declared variable num.But the stack memory is dereferenced as soon as the control shifts from the function f1 to the called function and the memory allocated for this type of variable is now dereferenced and contains garbage value.Still the value of num can be shown in the called function by accessing the returned address.Now if we call any other function say f2() and after the control comes back to the called function and we try to access the value num by its adress it will give unwanted result.This is because as soon as the second function f2() is called the variables in this function will overwrite the stack memory space which was previously taken by num variable..thus the pointer variable holding &num becomes dangling as its original pointee gets dereferenced.If we want to treat this pointer as not the dangling pointer we must declared it as static..so that the value of the variable has its scope beyond the function it is declared.
Wild pointer
Wild pointer is also another type of pointer we all use quite frequently infact every time.It is nothing but the pointer variable which has been declared but not defined.I'l give a code below to make it more simple-----
int wild(void)
{
int *p; // wild pointer
int num=1;
p=# // no more an wild pointer
}
I guess the above two is now clear to you....i'l come up with lot more
Dangling Pointer
Though most of us know this thing but few has a clear idea about this thing.But the most amusing thing is that we every body have used and is using this pointer unknowingly(except the most professionals one..who,I'm sure have done so previously in their life).
Dangling pointer is referred to that pointer which are pointing to a particular memory adress which has been already dereferenced already i.e., the object has been deleted without modifying the value of the pointer pointing its adress which still refers to the memory location of the dereferenced memory.
Now as the program continues it may refer that particular memory to new variables while the previous(now dangling) pointer is still referencing the memory..which might call for unpredictable behaviour.
An example of dangling pointer is when we make an array/block of memory using malloc/calloc.As soon as our function is over we call free() function to free it...but the pointer variable stays as the dangling pointer.
int main()
{
int *p;
p = (int *) malloc(sizeof(int));
/* ..... program steps .... */
free(p) ; // the pointer variable p becomes dangling
p=NULL; // the pointer variable is no longer dangling
}
Another dangling pointer example ----
int *f1(void)
{
int num = 10;
/* ...... program steps .....*/
return #
}
The above function returns the address value of the stack allocated localy declared variable num.But the stack memory is dereferenced as soon as the control shifts from the function f1 to the called function and the memory allocated for this type of variable is now dereferenced and contains garbage value.Still the value of num can be shown in the called function by accessing the returned address.Now if we call any other function say f2() and after the control comes back to the called function and we try to access the value num by its adress it will give unwanted result.This is because as soon as the second function f2() is called the variables in this function will overwrite the stack memory space which was previously taken by num variable..thus the pointer variable holding &num becomes dangling as its original pointee gets dereferenced.If we want to treat this pointer as not the dangling pointer we must declared it as static..so that the value of the variable has its scope beyond the function it is declared.
Wild pointer
Wild pointer is also another type of pointer we all use quite frequently infact every time.It is nothing but the pointer variable which has been declared but not defined.I'l give a code below to make it more simple-----
int wild(void)
{
int *p; // wild pointer
int num=1;
p=# // no more an wild pointer
}
I guess the above two is now clear to you....i'l come up with lot more
Thursday, November 5, 2009
Adventurism
This post deals with the books that make me dream to be a vagabond..and they are mainly written in bengali so i'l explainmy feeling also in bengali
Ami borabori choto thake khub Galper boi parte valo basi..Amar mate bangla deshe sarbokaler sera kishore sahityik halen Bibhutibhusan bandopadhay.Pratham jakhn Chader pahar pari takhn ami class 4er chatro.Galper nayak Shankarke jano chokher samne dekhte pachilam.Boita dhar niyechilam parar 1 didir kach thake.
Pare jedin nije boita kinechilam takhn gograshe parechilam.I just worship the book.Ki vabe 1ta pati bangali chele africar bistirno paharsreni r veld tapke hirer khani khojar kaje joriye gelo tai Chader Pahar boitar upojibyo.Bangla sahitye ato valo adventure uponash amar to mone hoy na r lekha hoyeche.Boita pore ami sapno dekhechilam amio 1din kadhe bag-pack jhuliye Chader pahar khujte jabo...jadio aj abdi chance hoyni kintu kono 1din jaboi a bapare amar khub icha....
Pare Dineshchandra Chattopadhayer-er lekha Duronto Igol poreo mugdho hoye gechilam.Vadrolok boita lekhar janyo either nije puro Tibet ghurechen or prachur..prachur..prachuuur parasona karechen oi part of world-er opor.Na hole ato valo vabe odesher description,culture,manasikata bojhano samvab hoto na.Boita lekha hoyeche Pamir valleyr opor.Ki vabe 1 dasyur pallay pare Pamirer Jura name 1 jubak russiar anti czar andoloner mukho naam hoye daralo tai niyei boita...Awesome..simply awesome.Ei Dineshchandra Chattopadhayer kishore der janyo besi boi lekhinnikano janina....kintu uni fatafati likhten jadi likhten tabe.Onar duronto igol charao Vaba series ami parechi..kintu tao vaba series duronto igoler nakher jugyi na..
Bibhutibhusan bandopadhayr r ek adventure uponash Hira Manik Jaleo jathesto valo kintu ager tar sathe kono tulonatei ase na..
Ami borabori choto thake khub Galper boi parte valo basi..Amar mate bangla deshe sarbokaler sera kishore sahityik halen Bibhutibhusan bandopadhay.Pratham jakhn Chader pahar pari takhn ami class 4er chatro.Galper nayak Shankarke jano chokher samne dekhte pachilam.Boita dhar niyechilam parar 1 didir kach thake.
Pare jedin nije boita kinechilam takhn gograshe parechilam.I just worship the book.Ki vabe 1ta pati bangali chele africar bistirno paharsreni r veld tapke hirer khani khojar kaje joriye gelo tai Chader Pahar boitar upojibyo.Bangla sahitye ato valo adventure uponash amar to mone hoy na r lekha hoyeche.Boita pore ami sapno dekhechilam amio 1din kadhe bag-pack jhuliye Chader pahar khujte jabo...jadio aj abdi chance hoyni kintu kono 1din jaboi a bapare amar khub icha....
Pare Dineshchandra Chattopadhayer-er lekha Duronto Igol poreo mugdho hoye gechilam.Vadrolok boita lekhar janyo either nije puro Tibet ghurechen or prachur..prachur..prachuuur parasona karechen oi part of world-er opor.Na hole ato valo vabe odesher description,culture,manasikata bojhano samvab hoto na.Boita lekha hoyeche Pamir valleyr opor.Ki vabe 1 dasyur pallay pare Pamirer Jura name 1 jubak russiar anti czar andoloner mukho naam hoye daralo tai niyei boita...Awesome..simply awesome.Ei Dineshchandra Chattopadhayer kishore der janyo besi boi lekhinnikano janina....kintu uni fatafati likhten jadi likhten tabe.Onar duronto igol charao Vaba series ami parechi..kintu tao vaba series duronto igoler nakher jugyi na..
Bibhutibhusan bandopadhayr r ek adventure uponash Hira Manik Jaleo jathesto valo kintu ager tar sathe kono tulonatei ase na..
Subscribe to:
Posts (Atom)
+of+On.jpg)