Вы находитесь на странице: 1из 11

Overview of C

C evolved from two previous programming languages, BCPL (Basic Combined


Programming Language) and B.
BCPL developed in 1967 by Martin Richard as a language for writing
operatingsystems software and compilers for operating system.B, a descendant of
BCPL,developed by Ken Thompson in 1970 at Bell Laboratories used to create early
versions ofthe UNIX OS.
C is a general-purpose, procedural programming language.It was first devised
byDennis Ritchie in the 1970s at AT & T bell Lab for the purpose of implementing the
UNIXOS.It initially became widely known as the development language of this
OS.Today,most operating systems are written in C and one of its major uses today is
inprogramming embedded systems.It is also used to write programs such as
powerfulword processor, database and graphics applications.
C over C++
C
-a procedural language
Support of numerical analysis and computer-based modelling in a wide range of
engineering and
other scientific disciplines, where the priority is to solve equations as quickly as
possible
C++ - an object-oriented language
Provides interactive software
Procedural languages are typically more appropriate than object-oriented
languagesfor engg and scientific calculations because the resulting programs can
make moreefficient use of the relevant hardware resources

C++ is C with added functionality and that around 90% of any C++ program is
actually C
The Structure of C Program
HEADER SECTION
*Optional

Contains name, short description, author of the program and date created

INCLUDE SECTION

Contains #include statements list of libraries

CONSTANTS AND TYPES SECTION


*Optional

Contains types and #define statements

GLOBAL VARIABLES SECTION


*Optional

Any global variables are declared here

FUNCTIONS SECTION
*Optional
User defined functions
MAIN PROGRAM SECTION
main()
{}
Header File
It contains definitions of functions and variables which can be incorporated into anyC
program by using the pre-processor #include statement.Standard header filesare
provided with each compiler, and cover a range of areas, string
handling,mathematical, data conversion, printing and reading of variables.
File Name
Related Functions
conio.h
Direct console I/O functions
ctype.h
Character-related functions

graphics.h
Graphics-related functions
math.h
Mathematical functions
stdio.h
Standard I/O functions
stdlib.h
Miscellaneous functions
string.h
String-related functions
A Simple C program
#include <stdio.h>
/* defines the routines for standard input
and output, such as printf, scanf, etc */
main()
/* informs the computer as to where the program starts */
{
/* signifies the begin segment of the program */
printf("Hello World!");/* this statement prints the word Hello World on the screen */
}
/* signify the end segment of the program */
Basic Output Statements
Command
Function
printf()
Used to print the output to the screen and
can be used with variables
puts()
Used to print a whole sentence on the
screen but cannot be used with variables
putchar()
Prints a single character on the screen

Controlling the Cursor position


The following characters, placed after the \ character in a printf() or puts()
statement, have the following effect.
Code
Meaning
\b
Backspace
\n
New line
\r
Carriage return
\t
Horizontal tab
\<enter>
Line continuation
\\
Backslash(\) character
\ or \
Single or double quote
Identifier
A name that is used to reference variables, function, label and various other userdefined objects. It should be

1 to 32 characters

First character must be a letter and subsequent characters being either

letters, numbers or underscore(_)

Composed of one-word

Should not be a Turbo C keyword

Variables (identifiers) need to be declared before you can use them in a program.
#include <stdio.h>
int x,y;
/* global variables declaration */
char let='A';

main()
{
float area, pi=3.1416, radius;
/* local variables declaration */
char stud_name[20];
}Basic Input Commands
Command
Function
scanf()
Used to scan the keyboard for information
Usually placed after printf() statements
Used with integer, float and double data
gets()
Reads a string of character entered at the
keyboard
Used with string data
getche()
Reads a character from the keyboard
The key pressed is echoed to the screen
automatically
getch()
Operates like getche() except that the
character typed is not echoed to the screen
Format:

scanf(var_for, &var_name);

where:
var_for - %d for int, %c for char, %f for float, %e for double
var_name name of the variable (identifier)

gets(string_var_name);

where:
string_var_name a variable used in the program which is of string type

var_name=getche();

where:

var_name the variable where the keypressed will be stored


or
getche();
/* this will cause the program to pause and wait until a key is
pressed
getch();
Basic parts of Turbo C Programming
i.
HEADER FILES those files providefunction prototype declaration for libraryfunctions.
The most common usedheaders or libraries are as follows:
a.
conio.h declares various functionsused in calling the Disk OperatinSystem (DOS)
console Input/Outputroutines.
b.
clos.h defines various constantand gives declarations for DOS and886 specific calls.
c.
float.h contains parameters for
floating input.
d.
graphics.h declares prototype for
the graphic function.
e. math.h
f. stdio.h
i.
clrscr (); - this is used to clear the textmode window or to clear the outputscreen
before running a program again.
ii.
{(start) this is the symbol used to
represents the beginning of the program.
iii.
}(stop) represents the end.
iv.
printf this is the reserved word used tooutput function that commands thecomputer
to display the message on thescreen which enclosed in doublequotations ().
v.
getche(); - gets the characters from the
console and
echoes on the screen.
vi.
Semi colon it is used to separate one
statement to another statement.

HISTORY of Turbo C

C stands for COMBINED PROGRAMMING LANGUAGE. Sometimes called SYSTEM


PROGRAMMING LANGUAGE or SPL. C parallels with UNIX in 1969, by Bell
Laboratories that sought an alternative to the Multics operating system for PDP-7
computer. The original version of Multics operating system was written in assembly
language.
The reason why the language is called C is that it is the successor to the language called
B which was developed by Ken Thompson in 1970 while working on DEC PDP-7. B was
the successor the language called BCPL (Basic Combined Programming Language)
which was developed by Martin Richards.
The C Language was designed in 1972 by Dennis Ritchie and first implemented at Bell
Laboratory using DEC PDP-11 computer.
In 1978 Brian Kernighan and Dennis Ritchie wrote the famous book called THE C
PROGRAMMING LANGUAGE.
C is often called a Middle Level Language but has a functionalism of a high-level
language and assembly language. C has only 32 keywords (27 from Kernighan and
Ritchie standard and 5 added by the ANSI Standardization committee).
Programming is a series of individual instructions to the computer that collectively
perform a meaningful task. It is the act of writing or coding computer instructions.
Program Source Code is the finished encoded instructions.
Programmer is the one who write the computer program and the first lady programmer is
Lady Augusta "Ada" Byron.
Translator is use to transform the source code into a machine language that the computer
can understand.
Linker is use to adjust the translated source file so that the program will run. Linking is
usually distinct from the compiling process on a machine running MS-DOS.
____
ALGORITHM
An Algorithm is a series of instructions that performs a specific task; It is a procedure that
can be used to solve a particular problem.
An Algorithm is a list of instructions for carrying out some problems step by step.

Sequence - All programs are based on sequential execution of sequence instructions.


Decision - The primary way in which you can alter the sequential execution of the
statements is to insert a decision step.
Branching is a decision steps that lets the execution flow in two or more directions.
Iteration - is often called looping. It causes an iteration instruction or a set of instructions
to be executed repeatedly.
Features of C-Language
1. Compact - C has only 32 standard keywords. Manufacturers of C-Compact language
compilers are free to use additional keyword.
2. Structured - C permits certain portions of a program to have structured private access
to data items stored in the computer memory, as well as the access to data items that are
accessible by the rest of the program.
3. Portable - tasks that requires interaction with peripheral device; Portable such as disk
drives or the video display, can be handled by standard library routines, which are not
part of the c-language itself.
4. Flexible - C has proved to be suitable for variety of programming tasks. C allows
relatively unrestricted conversion of data from one type to another, such as the
conversion of character to its numeric equivalent.
DIFFERENCES BETWEEN PASCAL AND C LANGUAGE

1. In Pascal, you can use lower case and uppercase but in C, you are only allowed to use
lower case only for input and output.1. In
2. In Pascal comments are enclosed by { } or (* *); In C comment are enclosed in /* */
3. In Pascal, we use BEGIN and END in C {left curly braces signifies the beginning of
the program while right curly braces signifies the end of the program.
4. In Pascal, (;) semicolon is used as statement separator. While in C, it is a statement
terminator.
5. In Pascal, we use write or writeln to print the output list. In C, printf as write and
printf("backslash n") for writeln.
6. In Pascal, we use read or readln to read from the keyboard. In C scanf, gets, getch,
getche, getchar in different kind usage.

7. In Pascal it uses unit file, in C built in header file.


8. In Pascal libraries, in C its header file and libraries.
BASIC ELEMENTS OF C PROGRAMMING LANGUAGE

1. Directives - Instructs the C preprocessor to act on text of directives the program.


2. Declarations - Establish names and define characteristics such as size, scope, and data
types.
3. Definitions - are declarations that allocate storage.
3.1 Function definition - declares the function name, its parameters, and the data type of
the value it returns.
3.2 Statement order - affects how you can use variables and statement order functions.
BASIC COMPONENTS OF A PROGRAM

1. Programs must obtain information from some input source


2. Programs must decide now this input is to arranged and stored
3. Programs must use a set of instructions to manipulate the input
3.1 Single statement
3.2 Conditional Statements
3.3 Loops
3.4 Subroutines
4. Programs must report the results of the data manipulation
5. Well written application incorporates all of the fundamentals just listed, expressed in
good modular design, self-documenting codes and good indention scheme.

What is difference between Turbo C, C++ and C#.?


C is structured programming language. Turbo C refers to a specific compiler made by
Borland that can be used for C programming.
C++ is a superset of C, meaning everything that you can do in C, you can do in C++. C+

+ also supports object-oriented programming through the use of classes and


inheritance.
C# is another language from Microsoft. It is similar in structure to Java and syntactically
to C++. It does not compile down to native machine code, but rather CIL, an
intermediate assembly type language. Therefore, to run a CIL or .NET program, the
appropriate runtimes must also be installed. C# is completely object-oriented unlike C++.

http://hubpages.com/hub/A-Brief-History-of-the-C-Language

Why Use C?
In today's world of computer programming, there are many high-level languages to
choose from, such as Pascal, BASIC, and Java. But C stands apart from all these
languages. This 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 logic
program. The C language compiler combines the capabilities of a low level language
with the features of a high level language. Therefore the language is suitable for
writing both system software as well as business packages & other software. You will
many compilers available in the market written in C.
Program written in c are very efficient and fast. This is due to its variety of data
types and powerful operators. It is many time faster than BASIC. This helps
developers in saving their valuable time.
C is a powerful and flexible language which helps system developers to deliver
various complex tasks with ease. C is used for diverse projects as operating
systems, word processors, graphics, spreadsheets, and even compilers for other
languages.
C is popular among professional programmers for programming, as a result, a wide
variety of C compilers and helpful accessories are available.
C is highly portable language. This means that a C program written for one
computer system (an IBM PC, for example) can be run on another system (a DEC
VAX system, perhaps) with little or no modification. Portability is enhanced by the
ANSI standard for C, the set of rules for C compilers.
Cs another striking feature is its ability to extend itself. A C program is basically a
collection of various function supported by C library (also known as header files). We
can also add our own functions to the C library. These functions can be reused in
other applications or programs by passing pieces of information to the functions, you
can create useful, reusable code.
Writing C program with user-defined functions makes program more simple and
easy to understand. Breaking a problem in terms of functions makes program
debugging, maintenance and testing easier.

As these features shows that C is an excellent choice for your first programming
language. But what is C++? You might have heard this term C++ and the
programming technique called Object-Oriented Programming (OOP). Possibly you're
wondering what the differences are between C and C++ and whether you should
learn C or C++.
C++ is a superset of C, means that C++ is the new improved version of C for the
latest programming needs. It contains everything C does, plus new additions for
OOP concept. If you will learn C++ later, you will find that almost everything which
you learnt in C is applicable in C++ too. In learning C, you are not only learning one
of today's most powerful and popular programming languages, but you are also
preparing yourself for other similar programming languages.
Another language that has gotten lots of attention is Java for its OOP and portability.
Java, just like C++, is based on C. If later you decide to learn Java, you will find that
almost everything you learned about C applies here.

Вам также может понравиться