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

Turbo C

Brief History
Brief History of C Programming Language C is a general-purpose
language which has been closely associated with the UNIX
operating system for which It was developed - since the system
and most of the programs that run it are written in C.

Many of the important ideas of C stem from the language BCPL,


developed by Martin Richards. he influence of BCPL on C
proceeded indirectly through the language B, which was written
by Ken Thompson, 1970 at Bell Labs, for the first UNIX system
on a DEC. BCPL and B are "type less" languages whereas C
provides a variety of data types.

In 1972 Dennis Ritchie at Bell Labs writes C and in 1978 the


publication of The C Programming Language by Kemighan & Ritchie
caused a revolution in the computing world. In 1983, the
American National Standards Institute (ANSI) established a
committee to provide a modem, comprehensive definition of C.
The resulting definition, the ANSI standard, or "ANSI C", was
completed late 1988.
Brief History
What: C is a high-level and general-purpose programming
language that is Ideal or developing firmware or '
portable applications Originally Intended for writing
system software, C was developed at Bell Labs by Dennis
Ritchie tot the Unix Operating System (OS) In the surly
1910..
Who: Dennis Ritchie. Dennis MacAlistair Ritchie
(September 9, 1941 - c. October 12, 2011) was an
American computer scientist. lie created the C
programming language and, with long-lime colleague Ion
Thompson, the Unix operating system.
When: C was developed at Ball Laboratories In 1972 by
Dennis Ritchie. Many of its principles and ideas were
taken from the earlier language B and B's earlier
ancestors BCPL and CPL.
Brief History
Where: C Is a general purpose, high-level language
that was originally developed by Dennis M. Ritchie to
develop the UNIX operating system at Bell Labs.
Operating System Platform: Was used to re-implement
the Unix operating system.

Why: C was developed at Bell Laboratories in 1972 by


Dennis Ritchie. Many of principles and ideas were
taken from the earlier language B and B’s earlier
ancestors BCPL and CPL. CPL (Combined Programming
Language) was developed with the purpose of creating a
language that was capable of both high level, machine
independent programming and would still allow the
programmer to control the behavior of the individual
bits if information.
Evolution of C(Standard)
TIME PERSONALITIES/THEORIES/
TECHNOLOGICAL INNOVATIONS
FRAME
1. Martin Richards
1966 2. Basic Computer Programming Language (BCPL)
3. Ken Thompson B Language
4. C-Language-Dennis Ritchie DEC PDP-11, UNIX
1972 OPERATING SYSTEM, Bell Telephone Lab. (AT&T)

5. Turbo C-Borland corp.~Borland C


Mid
1980
6. OOP (Object Programming)
1980 7. C++~the version of this approach (OOP)

8. Turbo C++, Borland C++


1988 9. Dev C++
Evolution of C (Standard)
TIME PERSONALITIES/THEORIES/
TECHNOLOGICAL INNOVATIONS
FRAME
1. UNIX SYSTEM V (as described in “The C Programming
1970 Language” by B. Kermighan & Dennis Ritchie)

2. Microcomputer
1970
3. American National Standard Institute
1983
4. 1989 Programming Language C
1988 5. ANSI or Standard C or C89

6. ISO(International Organization for Standardization


1990 7. ANSI C Standard
8. ISO/IEC 9899-1990 (sometimes called C 90)
Evolution of C

TIME PERSONALITIES/THEORIES/
TECHNOLOGICAL INNOVATIONS
FRAME
8. ISO/IEC 9899, 1999 or C99
1999 9. ANSI TURBO C
The Standard
1. The early informal standard (in 70’s) was the UNIX SYSTEM V
(as described in “The C Programming Language” by B.
Kermighan & Dennis Ritchie)
2. There were large numbers of C version because of the
growing popularity of microcomputer and the source code
accepted by most of these version is highly compatible.
3. There were no standard resulting to dicrepancies.
4. To rectify the prod. ANSI beginning in 1893. established
standard specific of C and ratified as ANSI X3.159 1989
Programming language C and is often referred to ANSI C,
Standard C or C89.
5. In 1903, the 'Marmite organ for standardize (ISO) adopted
the ANSI C Stand (with formatting changes) as ISO!IEC
9899.1990 or sometimes called C90. C89. and CO refer to the
same language.
6. The last ANSIIISO standardize was ISOIIEC 9899:1999 or
known as C99.
7. 7. ANSI Turbo C is a fart efficient compile/ and provides
both an Integrated programming environment and the more
traditional command-line version to satisfy the wide
variety of programming.
Middle Level
1. C – A mid level computer language. It combines the elements of high level
language with the functionalism of low level assembly language. It allows
the manipulating of bits, bytes and addresses the basic elements with
which the computer functions.
2. C code is very portable, means that is possible to adapt software written
for 1 type of computer to another. barn*. A program written for Apple II
can be moved easily to an IBM PC.
3. All high level programming language support the concept of Date type.
Data type defines a set of values that a variable can store along with a
set of operations that can be performed an the variable. Example. Common
data types are integers, characters, and real numbers,
4. C has five basic built in data types but is not a strongly typed language
like Pascal or Ada
5. C will allow almost all type conversions Example. Character and integer
types may be freely inter mixed in most expressions. G.
6. Traditionally C performs no run time checking such as array boundary
checking or argument type compatibility checking. These checks are
responsibility of the programmer.
7. Special feature of C7 allows the direct manipulation of bits, bytes,
words and pointers which suits system level programming. a_ C has only 32
keywords (27 from the Kermighan and Ritchie Standard and 5 added by the
ANSI standardize). (Turbo C contains II more keywords, BASIC For the IBM
PC contains 159 keywords.)
Structured Lang.
1. C is not strictly called book-structured language.
2. C Is commonly called a structured language because of structural
similarities to ALGOL, Pascal and modula 2. (Technically, a block
structure language permits procedures or functions to be declared
inside other procedure or functions. In this way the concept of "global
and "lot" are expanded through the use of scope rules which govern the
'visibility" of a variable or procedure.)
3. C does not allow the creation of functions within functions, it is not
really block structured.
4. The distinguished feature of a structure language is
compartmentalization of code and date. Compartmentalization, the
language's ability to section off and hide from the rest of the
program. All information and instruction necessary to perform a
specific tick
4.1. Subroutines, one way to achieve compartmentalization by employing
local C temporary variable so that the events that occur within them cause
no side effects in other parts of the program, making It very easy for the
C program to share sections of code.
4.2. In compartmentalized function you only need to know what a function
does, riot how it does it
Structured Lang.
4.3. Remember that excessive use of global variables (variables known
throughout the entire program) may allow bugs lo creep into a program by
allowing unwanted side effects. (Anyone who has programmed in BASIC is
well aware of this problem).
5. A structured language allows a variety of program possibilities by
widely supporting loop constructs, such as while, do while, and for. and
prohibits the use of goto (moo Is not tits tons of program control as It
Is in BASIC and FORTRAIN).
6. A structures language allows you to indent statements and does not
allow a strict field concept.
EXAMPLE OF STRUCTURED AND NON STRUCTURED — Pascal, Ada, C
NON STRUCTURED - FORTRAN, BASIC, COBOL
C's place in the world of language:
HIGHEST LEVEL: MIDDLE LEVEL:
Ada C
Modula-2 FORTH
COBOL Macro-assemble language
FORTRAN LOWEST LEVEL:
BASIC Assembly language
Standard Lang.
7. Structured language is newer, non structured language are older. The
clarity of structured language makes program and maintenance easier than
non structured language.
8. C’s, stand alone subroutine, the main structural component of C.
Function — the building block in which all program activity occurs, they
allow the separate task in a program to be defined and coded separately,
thus allowing your program to be modular. After a function has been
created, it should work properly in various situation without creating side
effects in other parts of the program stand alone function is critical in
larger projects.
9. Code block, another way to structure and compartmentalized code in C. a
logically connected group of program statements that is treated as a unit.
It is created by placing a sequence between opening and closing braces.
Example of a code block. If (x < 10) Print f ("too low, try again");
reset_counter (-1); Analysis: the two statement after the if and between
are both created if x is less than 10. The "f", the two statements and "y
form the code block. One of the statement execute without the other. Code
block allow many algorithms to be implemented with clarity, elegance and
efficiency and helps the programmer to conceptualize the true nature of the
routine.
Programmer Lang.
1. C is a programmer's language.
2. Not all programming language are for programmers. Example. COBOL and
BASIS was designed to enable non-programmers to read and presumably
understand the program and to solve simple problems.
3. C stands almost alone. It was created, influenced and field tested by
real working programmers, resulting to few restrictions, few complaints,
block structure, stand alone functions and compact set of keyboards;
making it amazing that a programmer can achieve nearly the efficiency of
assembly code, combined with the structure of ALGOL or Module 2, resulting
to established C as the most popular among topflight professional
programmers – due to the fact that C can often be used in place of
assembly language.
4. Assembly language uses a symbolic representation of actual binary code
that a computer executes. Each assembly language operation maps into a
single task for the computer to perform.

Advantage of Assembly Language


a. Gives the programmer the potential for accomplishing task with maximum,
flexibility and efficiency
Programmer Lang.
Disadvantage of Assembly Language
a. Notoriously difficult to use when developing and debugging a program
b. Furthermore, since assembly language is unstructured, the final program
tends to be spaghetti code. (tangled mass of jumps, calls and indexes
making the program difficult to read, enhance and maintain.)

5. C was used for system programming


a. System programming – is a part of the large class of program that forms
a portion of the operating system of the computation or its support
utilities.

Example of System programming:


• Operating system
• Interpreters
• Editors
• Assembly Program
• Compilers
• Database manager
Programmer Lang.
Disadvantage of Assembly Language
a. Notoriously difficult to use when developing and debugging a program
b. Furthermore, since assembly language is unstructured, the final program
tends to be spaghetti code. (tangled mass of jumps, calls and indexes
making the program difficult to read, enhance and maintain.)

5. C was used for system programming


a. System programming – is a part of the large class of program that forms
a portion of the operating system of the computation or its support
utilities.
Example of System programming:
• Operating system
• Interpreters
• Editors
• Assembly Program
• Compilers
• Database manager
6. Many programmer use C to program all task because of its portability
and efficiency since there C compiler for almost all computer! Making it
possible to take code written for machine and compile and run if on
another with few or no charges. Portable saves time and money and effort.
Programmer Lang.
7. Compilers produce tighter and faster object code than most other type
of compilers. Programmers like C in making all types of programming. C has
the speed and efficiency of assembly language and the extensibility of
Fourth but few if the restrictions of Pascal or Modula-2
8. Each C programmer can create and maintain a unique library and function
that have been tailored to his or her personality that can be used in many
different program because it allows and encourage separate compilation and
allows programmers to manage large projects easily and minimize
duplication of efforts.
9. Compilers VS Interpreters
• Compiler and Interpreter, the manner in which a program is executed.
Many programming languages can be either compiled or interpreted, but
some are usually compiled.
• The way a program is executed is not defined on the language in which it
is written
• Compiler and interpreted, are sophisticated programmer that operate on
your program source code.
10. Interpreter – reads the source code of a program one line at a time
and performs the specific instruction contained in that line.
11. Compiler – reads the entire program converts it into object code which
is a transaction of the program source into a form that can be directly
executed by the computer.
Programmer Lang.
12. Interpreter – must be present each time you run a program.
Example. In BASIC you have to execute the BASIC interpreter first, then
load the program and type RUN each time you want to use it. The BASIC
interpreter then examines the program one line at a time for correctness
then executes it. A slow process everytime a program runs.
13. Compiler – by contrast, after the compilation translates program into
object code only once that can be directly executed by the computer, by
the simple process of typing its name. Thus, compilation is a one time
cost, while interpreted code incurs and overhead cost each time a program
runs.
14.Two terms often used;
a. Compile time – refers to the events that occurs during compilation
b. Run time – refers to the event that occur while the program is actually
executing
15. The form of a C Programming
The 32 keywords as defined the ANSI standard
Auto continue eno if short switch volatile
Break default extern int signed type def while
Case do float long size of union
Char double for register static unsigned
Const else goto return stract void
Programmer Lang.
The turbo C extended keywords
Asm near _ss _ds huge
Interrupt far _cs pascal Cdecl _es

16. All C keywords are lower case. Upper case and lowercase are different.
17. All C programs consist of one or more functions. The only function
that absolutely must be present is called main () – the first function
called when program execution begins. Outlines what the program does,
outline is composed of function calls, main () is technically not a part
of C language but treat it as if it were and don’t use as the name of the
variable.
18.The general form of C Language programming
Global Declarations
Main ()
{
Local variable
Statement sequence
}
F1 () f2 ()
{ {
Local variables local variables

Statement sequence statement squance


} }
Programmer Lang.
19.The Library and Linking technically, It Is possible to create a useful,
fund)onal C Program that consistently of the statement actually created by
the programmer, but is rarely done because C does not prove any method of
performing I/O operation (within the definition of C language) (1/0 – input
/ output), as a result, most program include calls to various function
contained in C’s standard Library.
20. Turbo C comes with standard Library that provides function, a tie
perform most commonly needed tasks. When you call a function that is not
part of the program you wrote. Turbo C remembers its name. Later the LINKER
combines the code you wrote with the object code already found in standard
library and this process is Linking.
21. Relocatable format, the functions that are kept in the library, which
means that the member added for the various machine code instructions have
not been fully defined; only offset info. has been kept. The linking of the
program in the library. The memory of set are used to create the actual
addresses used.
22. Turbo C;s memory map, a compiled C program creates uses 4 logically
distinct regions of memory.
a. The program code memory region – the memory code that actually holds the
code
b. The global variables memory region – is where global variables are stored

c. The stack – are for numerous input activities


d. The heap – a region for memory which a program can be use by Turbo C,
dynamic allocation, function and others
Term for Turbo C/C++
a. Source code
b.Object code
c.Linker
d.Library
e.Compile tie

Atomic Data Types:


f.Run time

A. Character – used to hold ASCII char. or any 8 bit quantity


B. Integer – used to hold integer quantities
C. Floating Points – to hold real numbers
D. Double floating points – to hold real numbers
E. Valueless – to declare function as returning number value

Type Modifiers:
-basic data types may have various modifiers preceding them, used to alter
the meaning of the base type to fit the needs of various situation more
precisely.
Type Modifiers
Type Bit Range
Width
Character 8 0-255
Integer 16 -32788- 32767
Float 32 3.4-E38-
3.4+E38
Double 64 1.7E-308 –
Float 1.7E+308
Void - Valueless
Variables, Constants,
Operators and Expression
1. Variables and Constants are manipulated by operators to form expression
2.Identifier names, are used to reference variables, functions labels and
various other used defined objects are called identifiers, can vary from
1 – 32 characters, the 1st character must be a letter or an under score
“_”, bent characters being either letter, number of the underscore. Turbo
C allows $ to be used as an identifier name, but this is non-standard or
not recommended.

Correct Incorrect
Count 1count
Test23 Hi! There
High_there High..There
Variables, Constants,
Operators and Expression
3. In C, upper and lowercase are treated differently. Ex; Count, count, and
COUNT are 3 different identifiers.
4. An identifier cannot be the same as Turbo C keyword and should not have
the same name as functions that you wrote or that in the Turbo C library.
Variables, Constants,
Operators and Expression
Chapter 1
Introduction to Turbo C
An Introduction to programming using the Turbo C. programming Language

Pursuing five main goals:


1. To introduce the general techniques of programming, including methods
for accomplishing various sorts of programming tasks and how to apply them
generally, rather than to a single machine or to a single programming
language such as C.
2. To develop good techniques in programming habits, where C is an example
of structured programming language, and how various pitfalls are avoided
and how to climb out when you do fall in to these pits.
3. C lang. being noted for the terseness of its source code and efficiency
of its object code but also highly portable if correctly written. A widely
used language for all sorts of development work so by learning to program
in C, you will be acquiring a tool whose usefulness extends well beyond the
confines of its course.
Variables, Constants,
Operators and Expression
Chapter 1
Introduction to Turbo C
An Introduction to programming using the Turbo C. programming Language

4. Introduce you to significant and interesting applications of programming


which illustrate the tremendous range which computer applications can cover
and also illustrating valuable programming techniques.
5. To prepare you to create C application program of your own by the end of
this course by combining your knowledge of C, the general programming
techniques, and knowledge of applications to build and debug your own
applications program.
6. To learn the operation of the various components of the Turbo C
programming environment, i.e. concentrate on programming in the Turbo C
programming environment, which is an extremely popular and powerful
environment provides you with all the tools you need to create, test and
debug program on many of the most common
Turbo C
7.
This chapter ( as a modest
first step) Introduces you to
programming in general and C
in a particular, and to some
of the program will solve in
later chapters.
Structured Programming
and C
C is a programming language designed by Dennis
Ritchie in 1972 at AT&T Bell Laboratories.
a.) Was designed as a language designed for
system programming, as a way to fully
access the computer’s power without
becoming caught up in the tedious writing
of assembly language.
b.)One of the standard “work horse” programming
language and is commonly used to developed
commercial program
Structured Programming
and C
c.) Emphasizes structure programming
- a style of programming In which a
program is written as a sequence of the steps to be
executed one after the other.
The steps may involve sub-steps, each of which are
written according to the same rules. Each step is a
sequence of sub steps to be executed one after the
other. A structure program
proceeds in modular fashion from gross detail to
fine detall. This approach to program design is
called top-down design and will be discussed much in
later lessons.
The Exact Antithesis of
Structured Pro
GRAMMING is spaghetti code programming, in
which one statement can be followed by another
statement completely different part of the
program. (See Fig.1-1.)This commonly happens in
programming in BASIC(Beginner's all-purpose
Symbolic Instruction Code.)
The Exact Antithesis of
Structured Pro
Fig1-1 Spaghetti Code
100 IF X>5 THEN 200 ELSE
100
110 PRINT "THE VALUE OF
X IS";X’
120 END
200 X = X^2 + 5
210 GOTO 110
300 X=0
310 PRINT "X IS TOO
SMALL"
320 GOTO 120
The Exact Antithesis of
Structured Pro
10. Structured programming
~ uses certain types of statements called control structures,
which allow you to avoid spaghetti code and to write programs
which can be easily read & understood.
( In fig. 1-2. ,is shown a C program that accomplishes the same
thing as In fig1-1. Note that the logical flow of the program
(indicated by the arrow) is very simple: the statements follow
one after the other)
The Exact Antithesis of
Structured Pro
Fig. 1-2
if (x>5)
{
x=x*x+5;
printf ("x=%d\n",x);
}
{X=0;
printf ("x is too small \n");
}
The Exact Antithesis of
Structured Pro
11. In C, the main program statements can refer to
functions,
-Subprograms which perform specialized tasks, before the
functions are actually written, and then one can fill in
the required functions.
This approach to programming is called to-down design
13. C lends itself to complex programming tasks. In the
C style of programming, a complex program is broken down
into subprograms, each of which can be coded and tested
individually. The various need not even be programmed by
the same programmer!
14. C is only one programming lang. which emphasizes
structured programming. The first such language was PL/1
& recent structured programming language such as Ada,
Pascal, & Modula-2. The skills you learned in C language
can be carried over to these and other programming lang.
The Exact Antithesis of
Structured Pro
15. One reason why C is very popular is that it is
very portable.

16. Portable. In other words it is easy to get a


program written in C on one machine to run a
different machine. and mainly because the actual
language definition is very small. There are very
few features built into C. But you can expand the
language. The C language does not even have built-
in printing to the screen or reading from the
keyboard. However there are standard functions for
these and other task which are supplied with the C
complier.
The Turbo C Environment
16. C & its dialects. A spoken language typically
develops into a number of different dialects which
reflect local word usage and pronunciation. Analogously,
a computer language develops dialects which differ from
one another and reflects particular designer preferences.
There is a proposed “standard” version of C as defined in
a set of rules determined by a committee of the American
National Standards Institute (ANSI). These rules attempt
to bring order to the World of C Language version.

However, even according to the rules of standard,


local designers have a certain amount of direction in how
to implement various features of C. Suffice it to say
that all versions of C are slightly different from one
another and the degree to which they adhere to the
standard.
The Turbo C Environment
17. What is Turbo C?
- is a particular version of C
Developed by Borland International Corporation in 1987 &
designed to run on various microcomputer system, namely
those which use the operating system MS-DOS, which is the
opening for the IBM Personal Computer. Computer and its
compatibles.

18. The Components of Turbo C


Turbo C is more than just a version of C lang. Rather it
includes a complete environment in which to create, test
and run programs.
This programming environment consists of a number
of components:
1. Editor - a programmer's editor is used to create
program source code.
The Turbo C Environment
2. Extended C Language - This version C Is significantly
extended "bare bones" language of Ritchie's
specification, which includes enhancement which make
Turbo C compatible with the new proposed ANSI standard.
3. Compiler - a compiler is used to compile source
code Into machine language.
4. Debugger ~ is used for testing a program and locating
programming errors.
5. Run-Time Environment. The capability for running
programs within the Turbo C Environment
6. User Interface. - The various features of Turbo C are
integrated into a single program which allows you to
smoothly proceed from source code entry to compilation to
debugging to running without ever leaving the Turbo C
environment.
The Turbo C Environment
19. The Turbo C Main Screen
- introducing the elements of Turbo C dialect of the C
programming language.
- The best way of learning programming is by concrete
application and hands-on practice, meaning using the
Turbo C system to develop, test & run your programs.
-To pursue this approach let's precede the discussion of
the C language with an introduction using the Turbo C
system.

Starting Turbo C
This portion discusses the DOS as OS for running TB
20. The Main Menu Selections as displayed by the DOS.
The Turbo C Environment
20. The Main Menu Selections as displayed by the DOS.
Main Menu Selections - All operations of TC are selected
from the main menu. After an operation is completed, the
main menu is redisplayed to allow to choose another
operation.

The operation displayed on the main menu are:


1. File - to load or save C source, allows to
display a directory, execute a DOS command or exit from
Turbo C
2. Edit - start the editor. The contents of the
currently specified word file are displayed.
3. Run - run the currently compiled program. If the
current file has not been compiled, TC will automatically
compile the program before it runs it.
The Turbo C Environment
4. Compile - compile the currently specified file.
Three separation actions occur when compiling: a. First
the pre-processor is invoked B. then the compiler, C.
finally the loader
5. Project - allows to make one large program to
form several C-source code files.
6. Options - allows to specify technical aspects of
the TC compiler, linker or environment.
7. Debug - aids in debugging your TC program.
The Turbo C Environment
22. To Execute An Operation
1.use the left and right cursor key (or click left
button mouse) to move the highlighted bar over the menu
command of your choice.
2 use the up & down cursor key (or click left
button mouse) to move to the selection within the submenu
that you want to perform.
3.when you have highlighted the correct command,
press ENTER>.

23. Part of the programming process consist of the cycle:


(C BY DISSEC. Kelly-p3)
EDIT COMPILE EXECUTE
The Turbo C Environment
24. To enter, compile & run (execute) this program, begin
Turbo C & Enter the program Entering & Compiling a First
Program
1. To print on the screen
“Hello world! Eto. The complete procedure:

1. In the main menu window


A Click File, click Now
Option ... (TC+ creates noname.cpp file)
B. Now type the following:

25. The traditional first program in honour of Dennis


Ritchie who invented the C at Ball Laboratory in 1972
The Turbo C Environment
include <stdio.h> printf("\nOur Loader is etc");
#include <conlo.h> printf("\nAssistant leader is “);
main() /’ or int main(vold)"/ print(“ln Members are: ");
{ printf("\n a name");
printf("Hello, Worldl.In"); printf("Here is the dissection
printf("This is our first of the first program: );
pro"); getche();
printf("gram. We are In"); return 0;
printf(" Grade 9 Section "); } /”End of the first program.
printf(“ Linneaus and be"); Thank you. Good day"/
print("longs to Group 1.");

(The program is incomplete in text data but is sufficient for


running. More texts are to be added by student. For a complete
& correct texts for the source code, see unit:1, access the ms
turbo c & open the file "nciprntf.cpp)
The Turbo C Environment
26. To Run (execute), & save for the first time the
program & print the output, do as follows:
a. Select the File menu Save as Option... will display
the File Save as Option...
b. Within the Save as File dialog box, type the name
nc1pmtf.cpp & press Enter. TC will save the nc1prntf.cpp
27. Compiling Your C Program
a. Select the compile menu Build All option... will
display the compiling dialog box. (This step will not be
applied)
b. If the compiler successfully completes the
compilation, it will prompt you to press any key. If the
C compiler does not create the file nc1prntf.cpp, but
instead display error messages on your screen, you have
violated a C syntax rules as the next tip discusses.
The Turbo C Environment
c. If you successfully typed in the statements as shown
in Tip 2, the C compiler will create an executable file
named nc1prntf.exe.
To execute the nc1prntf.exe,
DO THIS!

1. CLICK RUN (or compile)


(Or alt+F9)
2. CLICK RUN AGAIN!
Or ctrl+F9 once or Twice!)

28. To go back to TC main menu... (To edit, to open new


File, or to quit).....
a.) press any key
The Turbo C Environment
29. Dissection of the 1st Hands on Source code
/” The traditional First etc”/
1... Are a comment.
1.1 Text that is bracketed by the starting pair
/” & the ending symbol pair “/ is ignored by
the compiler
1.2 It serves as documentation for the human
reader of the program.
2... Lines that begin with
a# are called pre processing directives
2.1 They communicate with the pre-processor.
2.2 This #include directives causes the pre-
processor to include a copy of the standard
header file stdio.h at this point
2.3 This header file is provided by the C system
The Turbo C Environment
2.4 the angle brackets around <stdio.h> to indicate
that this file is to be found in the “ usual
place”, which is system dependent.
2.5 We have included this file because it contains
information about prntf() function.
3...Int main (void)
The Turbo C Environment
Valid Variables Invalid Variables in C
•Num •Nuber1
•Float main (void)
•Num •Num 1
•{
•Num1 •Addition of program
•Radius = 40:
•_Num •1num
•Pi + 3.1415:
•NUM_temp2 •1_num
•Area= (2Xpi)(r):
•_num1 •365_days
•Prntf(the area of the
•Num__ •Int
circle is %f ,”,
•num_1 •char
Area):
•number_of_ Values •Continue
•Return 0;
•status_flag •_TIME_
•}
•Int •_DATE_
•/”End of program”/
•Char •_FILE_
•Continue •A Sample Program
•CONTINUE •/”Area of a circle”
_NAME_ •/”With radius and pi”/
•_SUM_ •#include<stdio.h>
•Float area, radius, pi
Components of Turbo C
Turbo C in more than just a version of the C Language. Rather, it
includes a complete environment in which to create, test and run
programs. This programming environment consists a number of
components:
1. Editor - a programmer's editor is used to create program source
code.
2. Extended C Language - This version C Is significantly exten "bare
bones" language of Ritchie's specification, which includes enhancement
which make Turbo C compatible with the new proposed ANSI standard.
3. Compiler - a compiler is used to compile source code Into machine
language.
4. Debugger ~ is used for testing a program and locating programming
errors.
5. Run-Time Environment. The capability for running programs within the
Turbo C Environment
6. User Interface. - The various features of Turbo C are integrated
into a single program which allows you to smoothly proceed from source
code entry to compilation to debugging to running without ever leaving
the Turbo C environment.
Coding Elements
1. A comment is a programmer-readable explanation or
annotation in the source code of a computer program.
They are added with the purpose of making the source code
easier for humans to understand, and are
generally ignored by compilers and Interpreters.
2. Pre processor directives are lines included in a
program that being with the character #, which make them
different from a typical source code text. They are
invoked by the compiler to process some programs before
compilation
3. The Main Function. In C, the "main" function is
treated the same as every function, it has a return type
(and in
some cases accepts inputs via parameters). The only
difference is that the main function is “called” by the
operating system when the user runs the program.
Coding Elements
4. The symbol { is referred to as open brace or open
curly bracket. Likewise, the symbol } is called close
brace onclose curly bracket. The curly brackets are used
for grouping purposes.
5. A declaration is a language construct that specifies
properties of an identifier, it declares what a word
(Identifier) means. Declarations are most commonly used
for functions, variables, constants, and classes, but
can also be used for other entities such as enumerations
and type definitions
6. An assignment statement sets and/or re-sets the value
stored in the storage location(s) denoted by a variable
name: In other words, it copies a value into the
variable. In most imperative programming languages, the
assignment statement for expression) is a fundamental
construct.
Coding Elements
10. The return statement is either "return" or "return
value", where value is a variable of other Information
back from the subroutine. Below is an example of how the
return statement could be used in the Pert programming
language.
11 . The symbols /” and”/ are used to group comments
Inside the program. Comments are not instructions, rather
they simply provide additional information (a textual
description) such as what the program is doing what we
the lnputs, what the outputs, c.
Character Conversions

When you want to print an expression to an output device,


you must especially the type of the expression and how
you want it to be formatted. Conversion specifications
are the symbol you use in the printf() control string to
do this. Each expression whose value you want to output
must have a corresponding conversion specification in the
control string.
Character Conversions
Conversion specifications for print and their uses
Conversion:
Conversion Out put
Specification
%c Character
%s String of characters
%d or %i Decimal integer
%e Floating point in e- notation
%f Floating point number in
decimal notation
%g Uses %f or%e ehichever is
shorter
%p pointer
Character Conversions
Conversion specifications for print and their uses
Conversion:
Conversion Out put
Specification
%u Unsigned decimal integer
%o Octal integer
%x Hexadecimal integer, using
lower case
%X Hexadecimal integer, using
upper case
Character Conversions
Conversion specifications for print and their uses
Conversion:
Conversion Out put
Specification
%%
Character Conversions
} Print a % sign
Here is a Ex. of printf() using conversion specification and another notation:
#include
Void main()
{
in t numa,numb;
numa = 1;
numb = 2;

printf(“this is”);
printf(“on &d line”,numa);

printf(“even thoughh we used more that 1 printf() function


%%
Printf(“Howevr, This \nwill be on % lines”,numb);
}
Output
This is on 1 line even though we used more that 1 print() function
However, This will ne on 2 lines
You may notice that the “\n” caused a line break. This is called
an escape sequence. The ff. Is a list of the escape sequence.
Character Conversions
Escape Sequences Meaning
New break
\a Alert. Plays a system beep
\b Backspace
\f Form feed
\r Carriage return
\t Horizontal tab
\v Vertical tab
\\ Prints a\
\’ Prints a’
\” Print a”
\0oo Prints an octal value(o represents an octal digit
\xhh Print a hexadecimal value (h reprents a hez digit)
Character Conversions
Description
The C library function int printf(const char "formal, ...)
conda formatted output to stdout.
Declaration
Following is the declaration for printf() function.
int printf(const char *format, .--)
Parameters
format - This is the string that contains the text to be
written to stdout. It can optionally contain embedded format
tags that are replaced by the values specified in subsequent
additional arguments and formatted as requested. Format tags
prototype is "%[flaga][width] (precision) [length] specific
which is explained below -
Character Conversions
Specifier Output
c Chracter
d or j Signed decimal int.
e Scientific notation using e character
E Scientific notation using E character
f Decimal floating point
g Uses the shorter of %e or %f
G Uses the shorter %E or %f
o Signed octal
s String of characters
u Unsigned decimal int.
x Unsigned hexadecimal int
X Unsigned hexadecimal int (capital letters)
p Pointer address
n Nothing printed
% Character

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