Thursday, May 05, 2016

Input |Output| statements in C

Input means giving the information to our compiler from keyboard as per our required program. Same Output means what you are giving based on that output will provide our compiler to us or user.Input Output Functions are predefined functions in c.There are used to print the message from one place to another place or any where.Following are the Input and Output functions in c.

  1. Formatted I/O Function.
  2. Un Formatted I/O Functions.

Formatted Input | Output FUnctions


These functions which are able to format that means printing the message (or)values are getting values from the keyboard.
  1. printf()
  2. scanf()

Printf()

This function is used for print the values or message on the output device.Most frequent used function in c language for output.
Syntax: printf("Display Message");

scanf()

This function which can be used to read an input from command line.It is the Input function it is used to get the values from the devices.

Ex: scanf("control string");
    Scanf("%d",&variable name); Here %d means used to read the integer values and we are passing &variable name to store the value read input.Here & represents the address of variable name. Commonly used scanf() format codes are given table
Control string Meaning
%c read a single character
%d read a decimal integer
%f read a floating point value
%g read a floating pont number
%l read a long floating point or double values

Points to Remember while using scanf


If we do not plan carefully, some crazy things can happen with scanf().
Given below are some of the general points to keep in mind while writing a scanfstatement.
  1. All function arguments,except the control string,must be pointers to variables.
  2. Format specifications contained in the control string should match the arguments in order.
  3. Input data items must be separated by spaces and must match the variables receiving the input in the same order.

Unformatted I/O functions


Un Formatted I/O functions works only with character data type.Those are getch(),getchar()

No comments:

Post a Comment