Introduction of Programming language c:
Introduction:
- The programming language C was developed by Dennis Ritchie in 1972 at AT & T's Bell Laboratories in california,USA.
- It was named as “C” because many of its features were derived from the earlier language “B”.
- C is one of the most popular programming languages. It is being used on various software platforms.
- C++ and Java are based on C.
Characteristics of C:
Simplicity:
C has richest collection of inbuilt functions, keywords and data types. It also resembles general English language. Also it follows a structured approach so it is to learn also.
Clarity:
The keywords and library functions available in C resembles common English words thus it helps to improve the clarity of the program.
Portability:
By the term portable we mean computer independent. The program made in C can be made to run on different machines thus increasing the efficiency of the program.
Modularity:
The programs made in C can be easily divided into small modules with the use of functions. This feature helps to increase the understandability of the program.
Easy Availability:
The C compilers are easily available and they require very less disk space for their storage. It is very easy
to load Turbo C complier in your computer.
Small Size:
C has only 32 keywords. This makes it relatively easy to learn as compared to other languages.
Structure of C Program:
- The documentation section consists of a set of comment lines giving the name of the program, the author and other details, which the programmer would like to use later.
- The link section provides instructions to the compiler to link the functions from the system library.
- The definition section defines all the symbolic constants.
- There are some variables that are used in more than one function. Such variables are called global variables and are declared in the global declaration section that is outside of all the functions. This section also defines all the user defined functions.
- Every C program must have one main() function section. This section contains two parts, declaration part and executable part. The declaration part declares all the variables used in the executable part.
- There is at least one statement in the executable part. These two parts must appear in the between the opening and closing braces. The program execution begins at the opening brace and ends at the closing brace. The closing brace of the main function section is the logical end of the program.
- All the statements in the declaration and executable part end with a semicolon (;).
- The Subprogram section contains all the user-defined functions that are called in the main function.
- User-defined functions are generally placed immediately after the main function, although they may appear in any order.
Writing First C Program:
Code:
//writing first C program.
#include<stdio.h>
int main()
{
printf("Compile Your Code");
return 0;
}
Output:
Compile your Code
#include<stdio.h>
- This is the preprocessor command that comes as the first statement in our code. All the preprocessor commands start with the hash (#) symbol.
- The #include statement tells the compiler to include the standard input output I/O library or header file in the program. This file has in built functions.
- It contains the data for input and output like reading the values from keyboard and printing the result on the screen.
int main( )
- int is the return value of the main function.
{ }
- The two curly brackets are used to group all the related statements of the main function.
- All the statements between the braces form function body.
printf(“Hello World”);
- The printf function is defined in the stdio.h file and is used to print text on the screen.
- The message to be displayed on the screen is enclosed in the double quotes and put inside the brackets.
Files used in a C Program:
Source Code File:
- This file contains all the source code of the program. The file extension of any C source code file is ‘.c’.
- This file contains C source code about the main function and other functions if any.
Header File:
- A header file is a file containing C declarations to be shared between several source files.
- A header file is a file with extension .h which contains C function declarations. You request to use a header file in your program by including it with the C preprocessing directive #include.
- A simple practice in C programs is that we keep all the constants, macros, system wide global variables, and function prototypes in the header files and include that header file wherever it is required.
Object File:
- Object files are generated by the compiler as a result of processing the source code file.
- The object file contains machine instructions for the CPU. Linker uses this object file to produce an executable file (.exe file) by combining the object files together.
- Object files have ‘.o’ extension, although some operating systems including Windows and MS-DOS have ‘.obj’ extension for the object file.
Binary Executable File:
- The binary executable file is generated by the linker. The linker links various object files to produce a binary file that can directly be executed.
- On Windows operating system, the executable files have ‘.exe’ extension.
Compiling and Executing C Program:
- C is a compiled language. Once the C program is written, you must run it through a C compiler that can create an executable file to be run on computer.
- While C program is a human readable, the executable file is a machine readable file available in an executable form.
- The mechanism for running a C program begins with program source file and ends with an executable file, which can be run on a computer.
- The source file contains the statements of a program written in C language. This source file usually contains ASCII characters and can be produced with a text editor, such as Windows notepad or and Integrated Design Environment. The source file is then processed by a special program called a compiler.
- The compiler translates source code into an object code.
- The object code contains machine instructions for the CPU and calls the operating system application.
- program interface(API). Next, object file is processed with another special program called linker.
- The output of a linker is an executable or runnable file.
0 Comments