Wednesday, 8 January 2014

C Programming Language Tutorial – II (Basic Input/output, Structure of program, Compilation & running process)

Basic I/O Functions
  • In C, there are no special keywords to perform input/output operations.
  • These operations are carried out by using library functions.
  • All console I/O functions produce only text based outputs.
  • However most compilers include screen control and graphics functions in their libraries.
The important task of any programming language is to handle input/output. C supports a set of library functions to handle I/O.
For I/O operations printf() and scanf() functions are used. These are formatted functions that allow the input read from keyboard and output displayed on the monitor to be formatted as per our requirements.
printf()
Its name comes from print formatted.  Format specifiers request that the argument be formatted and inserted into the string.
    
printf(“format specifier”,list of variables);
 


scanf()
It accepts the data from keyboard, formats it in a certain way as specified by the format specifiers and stores it in a variable.
scanf(“format specifier”,list of addresses of variables);
Preprocessor
·   Preprocessor directives are the instructions given to the compiler.
·   Preprocessor directives begin with # (hash).
·   Preprocessor directives are often placed in the beginning of a program before the main() is declared.
·   They are not translated into machine language, but are operated upon directly by the compiler before the compiling process begins.
C Library
Every C program consists of modules of pieces of code called functions. A function aims at accomplishing a specific task. With in a program you can write your own functions or you can use the functions that are provided by C library.
C library provides a rich collection of functions to the programmer for most common programming tasks. The functions provided by the C program are a part of C standard library.
How to use library files.
#include<header file name>
#include<stdio.h>
#include<conio.h>
#include<math.h>
Some Important Library Functions:
  • main() – Start of program
  • clrscr() – Clear screen
  • getch() – To display output
  • gets() – To read string
Structure of C Program
// name of the program
Or
/* name of the program, name of author, date, brief description, modification details etc.*/
#include<headerfiles>
#define constants
Function prototype;  /* if you declared your own function*/
return type main()
{ /* prog begins*/
            Declaration of local variables;
            Executable part;
            return;
} /* end of main() */
User define function()
{
            Function code;
}
Compiling And Running Program
Source File
This is single program file written by programmer.
This file has names which end in .c by convention.
Compiler
It translates the program written by user into binary format which can be directly understood by underlying operating system.
Object File
These are consists of function definitions in binary form, but are not executable by themselves.
These are created from source code file.
Linker
It links together a number of object files to produce an executable file.
Executable File
These are produce as the out of program. It generally ends with .exe.

No comments:

Post a Comment