0% found this document useful (0 votes)
15 views26 pages

Week 3

Uploaded by

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

Week 3

Uploaded by

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

WEEK 3: Elements of C

By
Michael Kumakech
Elements of C
• Every language has some basic Types Character Set
elements & grammatical rules.
Lower case a-z
• Starting with programming, we
should be acquainted with the basic Upper case A-Z
elements that build the language. Digits 0-9
1. Character Set Special !@#$%^&*
Character
• Communicating with a computer
White space Tab or new lines or space
involves speaking the language the
computer understands.
• In C, various characters have been
given to communicate.
Elements of C -- Keywords

• Keywords are the words whose


meaning has already been explained
to the C compiler.
• The keywords cannot be used as
variable names because if we do so
we are trying to assign a new
meaning to the keyword, which is not
allowed by the computer.
• There are only 32 keywords available
in C.
• Below figure gives a list of these
keywords for your ready reference.
Elements of C -- Keywords
Elements of C -- Keywords
Elements of C -- Keywords
Identifier
• In the programming language C, an identifier is a combination of
alphanumeric characters, the first being a letter of the alphabet or an
underline, and the remaining being any letter of the alphabet, any
numeric digit, or the underline.
• Two rules must be kept in mind when naming identifiers.
• The case of alphabetic characters is significant. Using "INDEX" for a
variable is not the same as using "index" and neither of them is the same
as using "InDeX" for a variable. All three refer to different variables.
• As C is defined, up to 32 significant characters can be used and will be
considered significant by most compilers.
• If more than 32 are used, they will be ignored by the compiler.
Data Type

• The Data type is a set of value with predefined characteristics.


• Data types are used to declare variable, constants, arrays, pointers,
and functions.
• Char is used to store any single character;
• int is used to store any integer value,
• float is used to store any single precision floating point number &
• double is used to store any double precision floating point number.
We can use 2 qualifiers with these basic types to get more types.
Data Type
In the c programming language, data
types are classified as follows...
1. Primary data types (Basic data
types OR Predefined data types)
2. Derived data types (Secondary
data types OR User-defined data
types)
3. Enumeration data types
4. Void data type
Primary data types

• The primary data types in the


C programming language are
the basic data types.
• All the primary data types are
already defined in the system.
• Primary data types are also
called as Built-In data types.
i. Integer data type
ii. Floating Point data type
iii. Double data type
iv. Character data type
Integer Data type

• We use the keyword "int" to


represent integer data type in c.
• We use the keyword int to
declare the variables and to
specify the return type of a
function.
• The integer data type is used with
different type modifiers like
short, long, signed and unsigned.
• The following table provides
complete details about the
integer data type.
Character
data type

The character data


type is a set of
characters enclosed
in single quotations.
Floating Point data types

• Floating-point data types are


a set of numbers with the
decimal value.
• Every floating-point value
must contain the decimal
value.
• The floating-point data type
has two variants...
• float
The float value contains 6 decimal places
whereas double value contains 15 or 19 • double
decimal places.
Floating Point data types

Type Storage size Value range Precision

float 4 bytes 1.2E-38 to 3.4E+38 6 decimal places

double 8 bytes 2.3E-308 to 1.7E+308 15 decimal places

long double 10 bytes 3.4E-4932 to 1.1E+4932 19 decimal places


Data Type
void data type

• The void data type means


nothing or no value.
• Generally, the void is
used to specify a function
which does not return
any value.
• We also use the void data
type to specify empty
parameters of a function.
Enumerated data type

• An enumerated data type is a


user-defined data type that
consists of integer constants and
each integer constant is given a
name.
• The keyword "enum" is used to
define the enumerated data
type.
Derived data types

• Derived data types are user-defined data types.


• The derived data types are also called as user-defined data types or
secondary data types.
• In the c programming language, the derived data types are created
using the following concepts...
1. Arrays
2. Structures
3. Unions
4. Enumeration
Arrays Data Type in C
Union Data Type

• A union is a special case of struct where the size of union variable is


not the sum of sizes of individual elements, as in struct, but it
corresponds to the largest size among individual elements.
• Hence, only one of elements can be used at a time.
• Look at following example:
Struct Data Type

• One of the unique features of C language is to store values of different


data types in one variable.
• The keywords struct and union are provided to derive a user-defined
data type.
• For example,
LABS & Practicals
LAB 1 - Integer
LAB 2 - Float
LAB 3
LAB 4

You might also like