Programming in c

I want answere of a question that
1.Why we us getch(); ?


  • Because we are slightly daft and think that DOS is still the hottest OS...

    Serious answer: getch() is a non-standard function that will grab the next symbol from the input buffer without waiting for enter. Standard C/C++ has no function that can do that.

    However, getch() is very much outdated since 1995.
    I posted a "wrapper" making it possible to use getch() in windows at [link=]this[/link] thread.
  • getch();

    is a function in conio.h
    its return type is "char"
    and it simply wait for user to press a key & then return the character.......

    hoped i answered the question

  • : I posted a "wrapper" ...

    I've run across this term before. Can you please define "wrapper?"

  • The term "wrapper" refers to code that is adapting to given external conditions, often with some overhead code because of it.

    In this case, the behavior and function prototype of getch() is already stated. You can only achieve the same functionality with Win API functions, yet you don't want to rewrite the old icky DOS code. Therefore you write a wrapper, to "wrap" in the Win API functions so that the main program doesn't need to be changed.


    A more pedagogical example of a wrappers is the type "Integer" in Java. In that language, generic programming is done by taking an "Object" as parameter.

    void func (Object obj);

    However, Java isn't a 100% pure object-oriented language because it still has the primitive data types "int", "char" etc just like C/C++. If you want to pass an int to a generic Java function, you can't, because an int isn't an "Object" like every user-defined class in the program.

    Therefore they invented a class called "Integer", which sole purpose is to contain one int variable. The class allows the caller to pass an int:

    int x;

    Integer is a wrapper class, because it wraps in the int type.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!