0% found this document useful (0 votes)
23 views

TC Introduction To Programming

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

TC Introduction To Programming

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 31

Introduction to Programming –

TURBO C

Prepared By: Miss Myra G. Flores- CCL


Instructress
What is Turbo C?
 C is like Pascal
 It is general purpose programming language
 It is started to run under Unix environment.
 Dr. Dennis Ritchie invented C programming language at
AT&T Bell Laboratories, New Jersey, U.S.A. in early
1970’s.
 It is considered as middle-level programming language
 C can manipulate the bits, bytes and even the computer
hardware memory addresses.
 The best tool for systems programming
 C language has been proven to be an extremely powerful,
expressive, and effective language for a wide variety of
programming language.

Prepared By: Miss Myra G. Flores- CCL


Instructress
Some examples of the uses of C
Operating system
Language compilers
Assemblers
Text editors
Print spoolers
Network devices
Modern programs
Databases
Language interpreters
Utilities

Prepared By: Miss Myra G. Flores - CCL


Instructress
Features of C language
A simple core language
Focus on procedural programming paradigm
Parameters are always passed by value
C encourages the creating of libraries user-defined
functions
C is flexible

Prepared By: Miss Myra G. Flores- CCL


Instructress
Data Types
Before a variable name (identifier) can be used in a C
program, it must be declared explicitly, together with
its corresponding data type.

Prepared By: Miss Myra G. Flores- CCL


Instructress
C Data Types
TYPE FORMAT MEANING EXAMPLES
int %d or %i A whole number 3, 7, +8, 1000000
float %f A number with 5.8, 9.0, -5.6789,
decimal point +0.0032
char %c A single letter, ‘B’, ‘r’, ‘*’, ‘3’
symbol, or number
enclosed within
two single quotes
char %s A string in c is “Ms.”, “Hi!”,
considered as a “143”, “I Love”
series of characters
double %f For bigger or 123456789.123
larger number with
a decimal point
void void() Value less 0
Prepared By: Miss Myra G. Flores - CCL
Instructress
Keywords
In C, keywords are reserved words that have a special
meaning.
Reserved b the programming language for expressing
various statements and constructs, thus, may not be
redefined by the programmer.

Prepared By: Miss Myra G. Flores - CCL


Instructress
Keywords in C
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while

Prepared By: Miss Myra G. Flores- CCL


Instructress
Identifiers
Identifiers – are composed of a sequence of letters,
digits, and the special character _ (underscore)
Avoid using names that are too short or too long.
Limit the identifiers from 8 to 15 characters only.

Prepared By: Miss Myra G. Flores- CCL


Instructress
Variables
Variables are identifiers that can store a changeable
value
These can be different data types.
Variable Declaration all variables must be declared
before they may be used.
Type variable list;
Example: int I, j, k;
char I, j, k;

Prepared By: Miss Myra G. Flores- CCL


Instructress
Rules for defining or naming
identifiers/variables
RULES EXAMPLES
1. It must consist only of letters, digits, _duh, num_1 (correct)
and underscore.
2. It should not begin with a digit. 1name, 3to3 (incorrect)
3. An identifier defined in the C printf, scanf (incorrect)
standard library should not be
redefined.
4. It is case sensitive; meaning ans ≠ Ans, aNs ≠ anS, Ans ≠ ANS
uppercase is not equal to the lowercase. (incorrect)
5. Do not include embedded blanks Large num (incorrect)
6. Do not use any of the C-language If , else, while, for
keywords as your variable/identifier.
7. Do not call your variable/identifier
by the same name as other functions
Prepared By: Miss Myra G. Flores- CCL
Instructress
Two Kinds of Variable
A. Local Variables
 Variables that are declared inside a function.
 It can only be referenced by statements that are inside the
block in which the variables are declared.
Example:
#include<stdio.h>
main()
{
int a, b, c;  Local Variables
________;
________;
}

Prepared By: Miss Myra G. Flores- CCL


Instructress
Two Kinds of Variable
B. Global Variables
 Variables that are known throughout the entire program
and may be used by any piece of code.
 They are created by declaring them outside of any
functions
Example:
#include<stdio.h>
int a, b, c;  Global Variables
main()
{
________;
________;
}
Prepared By: Miss Myra G. Flores- CCL
Instructress
Constants
Are the identifiers/variables that can store a value that
cannot be changed during program execution.
Example:
const int count = 100
Where 100 integer count has a fixed value of 100

Prepared By: Miss Myra G. Flores- CCL


Instructress
The Turbo C Environment
Four parts of Turbo C environment
1. Main menu
2. Editor status line and edit window
3. Compiler message window
4. Hot key quick reference line

Prepared By: Miss Myra G. Flores- CCL


Instructress
Main Menu
Instructs Turbo C to do something as indicated in the
list of menu.
It can be activated or can be used by pressing Alt Key
and the first letter of the menu.
For example: press Alt + F to activate File Menu

Prepared By: Miss Myra G. Flores- CCL


Instructress
Basic menus of Turbo C
1. File – used to load and save files, handles directories,
invokes DOS and exits Turbo C
2. Run – used to compile (check errors), links, and runs
the program currently loaded in the environment.
3. Compile – used to compile the program currently in
the environment.

Prepared By: Miss Myra G. Flores- CCL


Instructress
A.
Submenus under File Menu
Load (OPEN) – enables the user to select a file to be opened or
loaded into the editor
B. Pick (OPEN RECENT FILES) – enables the user to select a file
based on the last nine files previously opened or edited.
C. New – lets the user edit a new file or start new programs.
D. Save – store or saves the file currently in the editor.
E. Write to(SAVE AS) – enables the user to save a file using a
different filename
F. Directory – displays the content of the current working directory
G. Change Dir – enables the user to specify the defined path to
change the default path or directory
H. Quit – lets the user to exit or quit Turbo C

Prepared By: Miss Myra G. Flores- CCL


Instructress
Editor Status Line and Edit Window
It is where you type your program and where you see
the current line and column of the text you typed.
If you try to press Alt – I or Insert key, the word insert
disappears, meaning that the window is in overwrite
mode.
Press again insert key to return to the normal mode and
notice that the word insert appears again.

Prepared By: Miss Myra G. Flores- CCL


Instructress
Message Window
It is located the middle of edit window and hot keys.
It is used to display various compiler or linker
messages.

Prepared By: Miss Myra G. Flores- CCL


Instructress
Hot Keys
It is located at the bottom of Turbo C’s opening
screen.
It refers to shortcut or shorthand for selecting a menu.
Two sets of hotkeys are available the normal ones and
the alternate set.
Press the indicated key to use normal hotkeys.
For example, Press F1 to activate Help.
On the other hand, press Alt key briefly and the
corresponding Function Key to use alternate hotkeys.

Prepared By: Miss Myra G. Flores- CCL


Instructress
Structure of a Simple C Program
<#include directive>
<#define directive>
main()
{
<variable declaration section>
statements

}

Prepared By: Miss Myra G. Flores- CCL


Instructress
Explanations
A. #include directive – contains information needed by the
program to ensure the correct operation of Turbo C’s
standard library functions.
Example: #include <stdio.h>
B. #define directive – used to shorten the keywords in the
program.
Example: #define g gotoxy
C. Variable declaration section – it is the place where you
declare your variables.
D. Body of the program – start by typing main() and the
{ and } (open and close braces). All statements should
be written inside the { and } braces.

Prepared By: Miss Myra G. Flores- CCL


Instructress
Commonly used include files
in C language
1. alloc.h – declares memory management functions
2. conio.h – declares various functions used in calling
ibm-pc rom bios
3. ctype.h – contains information used by the
classification and character conversion macros.
4. math.h – declares prototype for the math functions
5. stdio.h – defines types and macros needed for
standard i/o
6. string.h – declares several string manipulation and
memory manipulations routines.
Prepared By: Miss Myra G. Flores - CCL
Instructress
Important Symbols
Symbols Meaning
\n It is a line char used to move the cursor to the next line
‘‘ Single quote is used for single character / letter
““ Double quote is used for two or more character
{ Open curly brace signifies begin
} Close curly brace signifies end
& Address of operator
* Indirection operator / pointer

Prepared By: Miss Myra G. Flores- CCL


Instructress
Input Statements
A statement used to input a single character or a
sequence of characters from the keyboard

Prepared By: Miss Myra G. Flores- CCL


Instructress
Keywords Meaning Syntax & example
getch a function used to input a single character getch();
from the keyboard without echoing the
character on the monitor ch = getch();
getche a function used to input a single character getche();
from the keyboard, the character pressed
echoed on the monitor, like the readln in ch=getche();
pascal
getchar a function used to input a single character getchar();
from the keyboard, the character pressed
echoed on the monitor, terminated by ch-=getchar();
pressing enter key
gets a function used to input sequence of gets();
character from the keyboard, spaces are
accepted, terminated by pressing enter key. gets(ch);
scanf a function used to input single character or scanf(“control string codes”,
sequence of characters from the keyboard, it identifier);
needs the control string codes in able to
recognized. spaces are not accepted upon scanf(“%d”, &num);
inputting. terminated by pressing spacebar.
Prepared By: Miss Charm Jao - CCL Instructress
Output Statements
A statement used to display the argument list or string on
the monitor
Keywords Meaning Syntax & example

printf a function used to display the argument list printf (“control string codes”,
on the monitor. it sometimes needs the argument list);
control string codes to help display the
remaining argument on the screen printf(“hello, %s, you are %d
years old”, name, age);
putchar a function used to display the argument list putchar();
or string on the monitor. it is like
overwriting a character putchar(tolower (ch));

puts a function used to display the argument list puts();


or string on the monitor. it does not need the
Preparedhelp of the
By: Miss control
Charm string
Jao - CCL codes.
Instructress puts(“hello”);
Format Strings
%c used for single char in C
scanf(“%c”, &ch);
printf(“%c”, ch);
%d decimal number (whole number)
scanf(“%d”, &num);
printf(“%d”, num);
%e scientific notation / exponential form
scanf(“%e”, &result);
printf(“%e”, result);
%f number with floating or decimal point
scanf(“%f”, &pesos);
printf(“%f”, pesos);
%o octal number
scanf(“%o”, &value);
printf(“%o”,
Prepared By: Miss Myra G.value);
Flores- CCL
Instructress
Format Strings
%s string of characters
scanf(“%s”, &str);
printf(“%s”, str);
%u unsigned number
scanf(“%u”, &nos);
printf(“%u”, nos);
%x hexadecimal number
scanf(“%x”, &value);
printf(“%x”, value);
%X capital number for hexadecimal number
scanf(“%X”, &nos);
printf(“%X”, nos);
%% print a percent sign
scanf(“%%”, &value);
printf(“%%”,
Prepared value);
By: Miss Myra G. Flores - CCL
Instructress
List of Commonly used Escape Sequences
\\ prints backlash
\’ prints single quotes
\” prints double quotes
\? Prints question mark
\nnewline

GOTOXY – is used to send the cursor to the specified location


Syntax: gotoxy(x,y);
Example: gotoxy(5,10);

Prepared By: Miss Myra G. Flores- CCL


Instructress

You might also like