Skip to main content

Introdution to C

Introduction to C
C Language is a powerful programming language developed by Dennis Ritchie at Bell Laboratories in 1970. C Language is a general purpose high-level language.
Most of its principles and ideas were taken from the earlier language B, BCPL and CPL. CPL (Common Programming Language) was developed jointly between the Mathematical Laboratory at the University of Cambridge and the University of London Computer Unit in 1960s.CPL was too large for use in many applications. In 1967, BCPL (Basic Combined Programming Language) was created as a scaled down version of CPL retaining its basic features by Martin Richards. Ken Thompson at Bell Labs, USA wrote his own variants of BCPL and called it B. In due course, the designers of UNIX modified it to produce a programming language called C. In 1970, a co-worker of Ken Thompson, Dennis Ritchie developed C Language by taking some of the generality found in BCPL and the B language into a more powerful language called C. Ninety percent of the code of the UNIX operating system and of its descendants is written in C. The name C comes being the successor of B and BCPLIn 1983, an ANSI standard for C emerged consolidating its international acceptance.

Features of C

C is powerful: The increasing popularity of C is due to its many desirable qualities. It is a robust language whose rich set of built-in functions and operators can be used to write any complex program. The C compiler combines the capabilities of an assembly language with features of a high-level language and therefore it is well suited for writing both System programs and Application programs.

C is a small language: It has only 32 keywords and its strength lies in its built-in functions and is easy to learn.

C is a structured programming language: language is well suited for structured programming, thus requiring the user to think of a problem in terms of function modules or blocks.

C is quick: A well written C program is likely to be as quick as or quicker than a well-written program in any other high-level language.

C is a core language: A number of common and popular programming languages like C++, Java, Perl, PHP etc are based on C. Having learnt C, it will be much easier to learn languages that are largely or in part based upon C.

C is stable: The ANSI standard for C was created in 1983. The language has not been undergone much changes then. The latest standard is C99 with only minor changes over ANSI C.

C is extendable: Another important feature of C is its ability to extend itself. A C program is basically a collection of functions that are supported by the C library. We can continuously add our own functions to the C library.

Compiling and Running C programs

A high-level source program must be translated first into a form the machine can understand. This is done by software called the Compiler. The compiler takes the source code as input and produces the machine language code for the machine on which it is to be executed as output.
Compiling and executing a C program requires you to work with four kinds of files:
1. Regular source code files. These files contain function definitions, and have names which end in ".c" by convention.
2. Header files. These files contain function declarations (also known as function prototypes) and various preprocessor statements. They are used to allow source code files to access externally-defined functions. Header files end in ".h" by convention.
3. Object files. These files are produced as the output of the compiler. They consist of function definitions in binary form, but they are not executable by themselves. Object files end in ".obj” in some operating systems (e.g. Windows, MS-DOS),
4. Binary executables. These are produced as the output of a program called a "linker". The linker links together a number of object files to produce a binary file which can be directly executed. They generally end in ".exe" on Windows.
C Program
C Program can be considered as collection of functions. A function is a sub program that contains instructions or statements to perform a specific computation. It is easy to define the functions and use it in C.A C program may contain several functions one of which must be main (). This function is the starting point of the program. Other functions are called from main. After executing the statements in a function the program control will be returned to the calling function. The function may be a user defined function or a built in library function.
The main components of a C program are

Preprocessor directives
Global Variables
User defined functions
Main function

The general syntax of a function is

returnvalue functioname(arguments)
variable decalarations
executable statements

Eg: void bio(void)

void main(void) /* program execution begins here */
clrscr(); /* calling a built in function to clear the screen */
bio();/* calling the bio function to print the name and college */
Output of the above program is:

The use of functions in C serves many advantages:
1. It facilitates top-down modular programming. In this programming style, the high level of the overall problem is solved first while the details of each lower-level function are addressed later.

2. The length of a source program can be reduced by using functions at appropriate places.

3. It is easy to locate and isolate a faulty function for further investigations.

4. A function may be used by many other programs. This means that a C programmer can build on what others have already done, instead of starting from scratch.


Popular posts from this blog

KTU-FOSS LAB Solutions

Write shell scripts to show the following  ( you can write menu driven programs)
 Currently logged user and his logname ( logname)  Your current shell ( echo $SHELL)  Your home directory ( echo $HOME)  Your operating system type (echo $OSTYPE)  Your current path setting ( echo $PATH)  Your current working directory ( echo $PWD )  Show Currently logged  users ( w or who -H)      Show only the user name of logged users in the host ( users)      Details of last login ( last cek....where cek is the user id )  About your OS and version, release number, kernel version ( uname -a or  cat  /proc/version)  Show all available shells ( cat /etc/shells )  Show mouse settings (cat  /sys/class/input/mouse*/device/name )  Show computer CPU information       CPU details      ( cat /proc/cpuinfo | more )       Show information on  CPU architecture ( lscpu)       Number of Processor core ( nproc)  Show memory information       Memory details ( cat /proc/meminfo | more )       Display file system disk usage ( d…

Important Directories and Files

Important Directories
/bin                            holds the “essential” Linux commands and utilities /boot                          holds files required for boot process (kernel, vmlinuz, grub) /dev                            holds device files (hard drive, USB, CD-ROM, etc.) /etc                             holds system configuration files /etc/init.d                    holds scripts to start/stop network services /etc/rc.d                     holds system startup/shutdown scripts /etc/X11                      holds configuration files for X-windows /home                        holds user home directories (except for the root account) /lib                               holds system/shared library files /lost+found                holds files restored after system crash /mnt                            used as temporary mount point for CD-ROM, floppy, etc. /opt                              typically where large software applications are installed /proc                           holds kerne…

ER Diagrams to Table

REDUCING E-R DIAGRAM TO TABLE - A database which conforms to an E R diagram can be represented by collection of tables .For each entity set and for each relationship set in the database, we will create unique tables, which is assigned the name of the corresponding entity set or relationship sets . Each table has a no. of columns which have unique names. Each row in the table corresponds to an entity or a relationship.

REPRESENTATION OF STRONG ENTITY SET -Let E be a strong entity set with descriptive attributes a1, a2....aN . We represent this entity by table called E with N distinct columns, each of which corresponds to one of the attributes of E.

REPRESENTATION OF RELATIONSHIP SET - Let R be a relation ship set involving entity set E1,E2....En Let attribute(R) consists of 'm' attributes We can represent this relation ship set by a table called R with m distinct columns, each of which corresponds to one of the attributes in attribute (R) plus the primary key of E1..En.