You are on page 1of 33

Turbo C Programming

ICT 10: CHAPTER 1 – LESSON3


QUICK REVIEW
Software Categories
• System SW
• Programs written for computer systems
• Compilers, operating systems, etc.

• Application SW
• Programs written for computer users
• Word-processors, spreadsheets, & other application
packages
Programs
• Programs are written in programming languages
• Pieces of the same program can be written in different PLs
• Languages closer to the machine can be more efficient
• As long as they agree on how to communicate

• A PL = programming language
• A special purpose and limited language
• A set of rules and symbols used to construct a computer program
• A language used to interact with the computer
Computer Languages
• Machine Language
• Uses binary code, Machine-dependent, Not portable
• A binary code represents text, computer processor instructions, or any
other data using a two-symbol system.
• Assembly Language
• Uses mnemonics, Machine-dependent, Not usually portable
• A mnemonic also known as a memory aid, is a tool that helps you
remember an idea or phrase with a pattern of letters, numbers, or
relatable associations.
• High-Level Language (HLL)
• Uses English-like language, Machine independent, Portable (but must
be compiled for different platforms)
What is a Compiler?
• A Compiler is a program or a software that transforms
programs written in High Level Programming Languages

What is a Turbo C?
• Turbo C is a C Programming Language Compiler that transforms
programs written in C to Assembly or Machine Code to create an
executable Program.
• Turbo C and Turbo C++ are compilers for C and C++ (C plus plus)
Programming Languages. They were originally developed by Borland
Software Corporation
Coding systems
• ASCII code
• The American Standard Code for Information Interchange (ASCII), uses a 7-
bit binary code to represent text and other characters within computers,
communications equipment, and other devices.

• Binary-coded decimal
• Binary-coded decimal (BCD) is a binary encoded representation of integer
values that uses a 4-bit nibble to encode decimal digits.
Syntax
• is the set of rules that defines the combinations of symbols that are
considered to be correctly structured statements or expressions in
that language.
• Syntax therefore refers to the form of the code, and is contrasted
with semantics (the meaning).

Semantics
• is the field concerned with the rigorous mathematical study of the
meaning of programming languages.
Data Types
Primitive Data Types
• These data types are built-in or predefined data types
and can be used directly by the user to declare variables.
• Integer
• Character
• Boolean
• Floating Point
• Double Floating Point
• Valueless or Void
• Wide Character
Primitive Data Types
• Integer:
• Keyword used for integer data types is int. Integers typically requires 4 bytes of
memory space and ranges from -2147483648 to 2147483647.

• Character:
• Character data type is used for storing characters. Keyword used for character
data type is char. Characters typically requires 1 byte of memory space and ranges
from -128 to 127 or 0 to 255.

• Boolean:
• Boolean data type is used for storing boolean or logical values. A boolean variable
can store either true or false. Keyword used for boolean data type is bool.

• Floating Point:
• Floating Point data type is used for storing single precision floating point values or
decimal values. Keyword used for floating point data type is float. Float variables
typically requires 4 byte of memory space.
Primitive Data Types
• Double Floating Point: Double Floating Point data type is used
for storing double precision floating point values or decimal
values. Keyword used for double floating point data type is
double. Double variables typically requires 8 byte of memory
space.
• void: Void means without any value. void datatype represents
a valueless entity. Void data type is used for those function
which does not returns a value.
• Wide Character: Wide character data type is also a character
data type but this data type has size greater than the normal 8-
bit datatype. Represented by wchar_t. It is generally 2 or 4
bytes long.
Derived Data Types
• The data-types that are derived from the primitive
or built-in datatypes are referred to as Derived Data
Types.
• Function
• Array
• Pointer
• Reference
Function
• A function is a block of code or program-segment
that is defined to perform a specific well-defined task.
• A function is generally defined to save the user from
writing the same lines of code again and again for the
same input. All the lines of code are put together
inside a single function and this can be called
anywhere required. main() is a default function that is
defined in every program of C++.
SYNTAX:

FunctionType FunctionName(parameters)

OUTPUT:
m is 20
Array
• An array is a collection of items stored at continuous memory
locations. The idea of array is to represent many instances in one
variable.
SYNTAX:

DataType ArrayName[size_of_array];

OUTPUT:
5 2 -10 5
Pointers
• Pointers are symbolic representation of addresses.
They enable programs to simulate call-by-reference
as well as to create and manipulate dynamic data
structures.
SYNTAX:

datatype *var_name;

OUTPUT:

Value at ptr = 0x7ffc10d7fd5c


Value at var = 20
Value at *ptr = 20
Reference
• When a variable is declared as reference, it becomes
an alternative name for an existing variable. A
variable can be declared as reference by putting ‘&’
in the declaration.
OUTPUT:

x = 20
ref = 30
Abstract or User-Defined Data Types
• These data types are defined by user itself.
• Class
• Structure
• Union
• Enumeration
• Typedef defined DataType
Class
• The building block of C++ that leads to Object-Oriented programming is
a Class. It is a user-defined data type, which holds its own data members
and member functions, which can be accessed and used by creating an
instance of that class. A class is like a blueprint for an object.
Syntax:
OUTPUT:
Geekname is: GeeksForGeeks
Structure
• A structure is a user defined data type in C/C++. A structure creates a data type that can be
used to group items of possibly different types into a single type.
Syntax:
struct address {
char name[50];
char street[100];
char city[50];
char state[20];
int pin;
};
OUTPUT:
10, 20
Union
• Like Structures, union is a user defined data type. In union, all
members share the same memory location.
OUTPUT:

After making x = 2:
x = 2, y = 2

After making y = 10:


x = 10, y = 10
Enumeration
• Enumeration (or enum) is a user defined data type in C. It is mainly
used to assign names to integral constants, the names make a
program easy to read and maintain.

Syntax:
enum State {Working = 1, Failed = 0};
OUTPUT:
2
OUTPUT:
c
Typedef 
• C++ allows you to define explicitly new data type names
by using the keyword typedef. Using typedef does not
actually create a new data class, rather it defines a name
for an existing type.
Syntax:
typedef type name;

You might also like