C

Introduction to C program

Main details about C:

Lets understand what a Program is :

A Program is a set of instructions to solve a problem.
C language is a general purpose, basic combined programming and structured   programming language .

The C language has been developed by Dennis ritchie.
The C language has been developed at AT&T bell labs,USA.
C is closely associated with UNIX.
The C language has following numerous features as: 

     1. Portability
     2. Flexibility
     3. effectiveness and efficiency
     4. Reliability
     5. interactivity

Execution of C program contains 4 steps:
(1)Creating program
(2)Compiling program
(3)Link program
(4)Executing program

1. Creating a program :
An editor like notepad or wordpad is used to create a C program. This file
contains a source code which consists of executable
code.The file should be saved as “filename.c” extension only.

2. Compiling the program :
The next step is to compile the program. The code is compiled by using
compiler. Compiler converts executable code to binary
code i.e. Object code. (cc filename.c or gcc filename.c or gcc o filename
filename.c or F9 dependence on plotform)

3. Linking a program to library :
The object code of a program is linked with libraries that are needed for
execution of a program. The linker is used to link
the program with libraries. It creates a file with '*.exe' extension.

4. Execution of program :

The final executable file is then run by dos command prompt or by any other
software.

The program to print the statement called “hello,world”:
#include <stdio.h>
main()

{
printf("hello, world\n");
}
The above program prints the statement called ‘hello, world’
In UNIX operating system the file name should be end with ‘.c’.Running a program depends on the system that we are using. As a specific example, on the UNIX operating system we must create the program in a file ,whose name ends in ``.c'', such as hello.c, then compile it with the command ‘cc hello.c’
The compiler will produce an executable file called ‘a.out’.
#include <stdio.h>
The above line tells the compiler to include information about the standard
input/output library.

These line appears at the beginning of many C source files.
#include <stdio.h> include information about standard library
main()
define a function called main that received no argument
values
{
statements of main are enclosed in braces
printf("hello, world\n"); main calls library function printf to print this sequence of characters
}
\n represents the newline character.In C program the printf never supplies the newline automatically. So the programmer use ‘\n’ to print newline
In C program every statement ends with semicolon(;),the semicolon indicates the
end of the statement.
C provides ‘\t’ for tabspace ,’\b’ for backspace, ‘\”’ for quote and ‘\\’ for the backslash itself.
‘main()’is the only function all C programs must contain.‘{}’ punctuation is used to signal the beginning and end of code blocks. Main function is a User defined function. Printf doesn’t supplies newline character. Comments doesn’t affects the execution speed.

C program uses compiler process.

The C language can be used in
UNIX operating system
LINUX operating system
MS DOS operating system
The C programs are case sensitive.
The compiler compiles the complete program in one stroke.
Error type :
Syntax Error :- Violation of rule of the language result in the
syntax error. Compiler detect it at the time of compilation.
Logical Error :- This cause incorrect result. This is due to the lack
of emphasis on the algorithm development.
Run-time Error :- Errors such as mismatch of data type or
referencing an out of range array element or division by zero result
in the run-time error. Program may give wrong result.

No comments:

Post a Comment