what is difference between getchar,putchar functions and
printf and scanf function? does putchar show output only
when input given to it

Answer Posted / mudra

The standard C library provides several functions and macros for character 1/0. Here we consider the getchar and putchar macros. As these macros read or write a single character, they are typically used in a loop to read/write a sequence of characters.



A macro call is similar to a function call. Thus, it consists of a macro name followed by a comma-separated argument list enclosed in a pair of parentheses. If a macro does not require any arguments, the pair of parentheses must still be used.

The getchar macro is used to read a single character from the standard input stream, i. e., the keyboard. A call to get char takes the following form: getchar (). This macro waits until a key is pressed and then returns its value (after converting to integer). The value returned can be assigned to a variable of type char. However, note that this macro actually reads the data from the input buffer which is processed by program only when the Enter key is pressed. Thus, getchar does not return a value until the user presses the Enter key. As a result, it is not suitable for interactive programs. We can instead use the getch and getche functions which directly read the data from the keyboard.

The putchar macro is used to write a single character on the standard output stream (i.e., display). A call to this macro takes the following form: putchar (c), where c is an integer expression representing the character being written. Although this macro expects an argument of type int, we usually pass a character to it. The argument value (c) is converted to unsigned char and written to the standard output stream.

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a global variable in c?

766


Can a function argument have default value?

897


What is the use of a static variable in c?

776


What is the translation phases used in c language?

823


What is the explanation for prototype function in c?

737


What is difference between stdio h and conio h?

1099


how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?

1674


Multiply an Integer Number by 2 Without Using Multiplication Operator

532


Explain what does it mean when a pointer is used in an if statement?

822


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

3379


How do you initialize pointer variables?

791


What is a double c?

758


differentiate built-in functions and user – defined functions.

856


Why doesnt long int work?

790


what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)

2112