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)
{
printf(“Neethu\n”);
printf(“CEK”);
}

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:
Neethu
CEK

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.

Comments

Popular posts from this blog

Introduction to Data Structures

Visit My Data Structure Blog for Programs... It is important for every Computer Science student to understand the concept of Information and how it is organized or how it can be utilized. If we arrange some data in an appropriate sequence, then it forms a Structure and gives us a meaning. This meaning is called Information . A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. Data may be organized in many different ways. The logical model of a particular organization of data in a computer is called data structure. The choice of the model based on two considerations. It should be reflect the data in the real world. It should be simple that one can effectively process the data when necessary. E.g. Array, linked list, stack, queue, tree, graph Data structure can be classified into two: Linear: A data structure is said to be linear if its elements form a sequence E.g. Array, linked list, stack, queue Non-Linear: A dat

Basic Linux Commands For Beginner's

Basic Linux Commands for Beginners Linux is an Operating System’s Kernel. You might have heard of UNIX. Well, Linux is a UNIX clone. But it was actually created by Linus Torvalds from Scratch. Linux is free and open-source, that means that you can simply change anything in Linux and redistribute it in your own name! There are several Linux Distributions, commonly called “distros”. A few of them are: Mint Ubuntu Linux Red Hat Enterprise Linux Debian Fedora Kali Linux is Mainly used in Servers. About 90% of the Internet is powered by Linux Servers. This is because Linux is fast, secure, and free! The main problem of using Windows Servers are their cost. This is solved by using Linux Servers. Forgot to mention, the OS that runs in about 80% of the Smartphones in the World, Android, is also made from the Linux Kernel. Yes, Linux is amazing! A simple example of its security is that most of the viruses in the world run on Windows, but not on Linux

KTU-FOSS LAB Solutions

Write shell scripts to show the following  ( you can write menu driven programs)  Currently logged user and his logname   ( logname, id -un, echo $USER)  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 mec  ;where mec 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 Processo