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

Writing a Bash Shell Script

What Are Shell Scripts? In the simplest terms, a shell script is a file containing a series of commands. The shell reads this file and carries out the commands as though they have been entered directly on the command line. The shell is somewhat unique, in that it is both a powerful command line interface to the system and a scripting language interpreter. As we will see, most of the things that can be done on the command line can be done in scripts, and most of the things that can be done in scripts can be done on the command line. Writing Your First Script And Getting It To Work To successfully write a shell script, you have to do three things: Write a script Give the shell permission to execute it Put it somewhere the shell can find it Writing A Script A shell script is a file that contains ASCII text. To create a shell script, you use a text editor . A text editor is a program, like a word processor, that reads and writes ASCII text files. There are...

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...

Shell

Definition of the Shell Shell is an interactive environment which provides an interface to an Operating System. It gathers input from user and execute the commands. Bourne shell(sh)- 1977 The Bourne shell was introduced. The Bourne shell(sh), by Stephen Bourne at AT&T Bell Labs for V7 UNIX, remains a useful shell today (in some cases, as the default root shell). The Bourne shell was developed after working on an ALGOL68 compiler, so its grammar is more along the lines of Algorithmic Language (ALGOL) than other shells. The source code was developed in C. The Bourne shell served two primary goals: Executing UNIX/Linux commands for the operating system,i.e, command line interpreter Writing reusable scripts that could be invoked through the shell,i.e, scripting In addition to replacing the Thompson shell, the Bourne shell offered many other advantages over its predecessors such as control flows, loops, and variables into scripts, providing a more functional language to...