The greatest mistake you can make in life is to be continually fearing you will make one

Tuesday 21 September 2010

Questions on Data Input and Output

  1. What are the commonly used input and output functions in c? How are they accessed?Solution


    * C has 6 popular data input and output library functions. They are getchar, putchar, printf, scanf, gets and puts.
    * These functions handle data transfer between computer and the input/output device (keyboard,monitor)
    * The functions getchar and putchar allow single characters to be transferred into and out of the computer.
    * The functions printf and scanf allow the transfer of single characters, numerical values and strings
    * The functions gets and puts handle input and output of strings.
    * To use these functions in a program the standard input output header file stdio.h must be included in the program.
  2. What is the header file needed to include the input and output functions?
    Solution



    To include the standard c input and output functions getchar, putchar, printf, scanf, gets and puts the header file #include< stdio.h > must be included in the program
  3. What happens when an end of file condition is encountered when reading characters using getchar() function?Solution



    If an end of file condition is encountered when reading a character using getchar() function , the value of the symbolic constant EOF will  automatically returned . The value of EOF is -1
  4. When entering data via the scanf function must octal data be preceded by 0 and must hexadecimal data be preceded by 0x?Solution



    Octal values need not be preceded by a 0 and hexadecimal values need not be preceded by 0x or 0X in scanf function
  5. How are unrecognized characters within the control string of a scanf function interpreted?Solution


    Un recognized characters within the control string are expected to be matched by the same characters in the input data. The unrecognized characters will be read into the computer but not assigned to an identifier. Execution of the scanf function will terminate if a match is not found
    Example:     scanf("%d * %d",&a,&b);
    the accepted  input is 5 * 4. If you give a and b as 5 and 4 then the program will stop executing as the expected character * is not found. so a is assigned to 5 and bis assigned to 0
  6. What is the difference between f-type conversion,e-tye conversion and g-type conversion when outputting floating point data with a printf function?
  7. What is the conversion character i represent in scanf and printf function?Solution



    "i" represent the dataitem is a decimal,hexadecimal or octal integer


  8. What is the minimum field width specifies and Where is it located?
    Solution


    It specifies the smallest field in which a value is to be printed. It is used in a conversion specification, and if present, it is placed immediately following the % sign.
  9. When the conversion specification is %, what is its minimum secification?
    Solution


    The size of the number being printed (including a minus sign, if the number is negative.)
  10. What is the meaning of 'f' in printf statement?
    Solution



    "f" stand for either formated or function

  11. In printf() function what is the output of printf("%d")?
    Solution
    When we write printf("%d",a); the compiler will print the value of a. But here nothing after "%d% so compiler will print garbage value

No comments:

Post a Comment