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

Lecture5 Simple C DataT Ypes

The document outlines fundamental data types in C programming, including bits, bytes, words, and various data types such as integers, floating points, and void. It explains the significance of data types in memory storage and operations, as well as constants and their definitions. The summary includes basic data types like int, long, float, double, char, and void.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Lecture5 Simple C DataT Ypes

The document outlines fundamental data types in C programming, including bits, bytes, words, and various data types such as integers, floating points, and void. It explains the significance of data types in memory storage and operations, as well as constants and their definitions. The summary includes basic data types like int, long, float, double, char, and void.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

C Programming:

Simple Data Types

1
Fundamental C Data Types [1]
 Bits, Bytes and Words
 The smallest unit of memory is called a bit.
 It can hold one of two values: 0 or 1.
 The bit is the basic block of computer memory.
 A byte is 8 bits.
 A word is a natural unit of memory for a given computer design.
 Some computers have 32-bit words and more recent computers have
64-bit words.
 The larger a word is the more information it can store.
 The concept of types is important in that it determines the space necessary
to store the values of a particular type, and which valid operations are
defined on certain types.
 Whenever an identifier, (variable name, function name, formal parameter
name, user-defined type name, etc.) is declared to be of a certain type, the
type name always comes first, followed by the identifier.
 <type> <identifier> …
 Note Even though a type name may consist of more than one word, it
must still be considered as one autonomous type.

© Prof Suvendi Rimer, UJ


Fundamental C Data Types [2]
 The C language provides
several fundamental data types.
1. Basic Types: arithmetic types
classified into:
a) Integer types
b) Floating point types
2. Void type: no value available.
a) Function that returns no
value has the return type
void.
b) Function with no parameter
can accept void.
3. Derived types include:
a) An array type
b) Function type

© Prof Suvendi Rimer, UJ


void and scalar data types
 The void data type indicates ‘nothing’.
 The void keyword may be used
 to indicate that a function does not
return a value, e.g. void do_it(int a)
 To indicate that no parameters are
required in the function definition, for
e.g., int do_it(void)

 Scalar Types
 Scalar types are largest group and are
called scalar because the types have only
one dimension (one value).
 There are three sub-groups of scalar
types, namely: arithmetic, pointer and
enumerated types.

© Prof Suvendi Rimer, UJ


Arithmetic data types [1]
 These types are numeric types on which arithmetic operations, amongst
others, can be performed.
 Integer Types
 An integer type is a whole number.
 The sizes of the integer data types are very implementation dependent and are
therefore the types most closely associated with the host computer architecture.
 The sizes of these types range from 8 bits to 64 bits on some computers.
 In the following table, the square brackets […] indicate an optional word, since
without it the compiler will accept it anyway as the default:

Integer Type Description


[signed] char Signed character type
unsigned char Unsigned character type
[signed] short [int] Signed short integer type
[unsigned] short [int] Unsigned short integer type
[signed] int Signed normal integer type
[unsigned] int Unsigned normal integer type
[signed] long [int] Signed long integer type
[unsigned] long [int]
© Prof Suvendi Rimer, UJ Unsigned long integer type
Arithmetic data types [2]
 Floating Point Types
 A floating-point number more or less corresponds to a real number.
 Integers are whole number, whereas floating point numbers can represent
both whole and fractional numbers.
 No bit operations are allowed on floating point types.
 The three floating point types are:
 float
 double
 long double
 Floating point numbers can represent a much larger range of values than
integers, but tend to be slower than integer operations.

 Character Data Types


 A char variable is used to store a single character.
 A character constant is formed by enclosing the character within a pair of
single quotation marks.

© Prof Suvendi Rimer, UJ


Constants
 Constants refer to fixed values that the program may not alter during its
execution. These fixed values are also called literals.
 The C pre-processor allows for a means to define constants which can then
be used later in a program.
 The constant data types must be defined before the main function.
 The constant name should be written in capitals and does not have a semi-
colon at the end. The use of constants is mainly for making your programs
easier to understand and modify by others and yourself in the future.
 Constants can be of any of the basic data types like an integer constant, a
floating constant, a character constant, or a string literal.
 Constants are treated just like regular variables except that their values
cannot be modified after their definition.

 The format of a constant is shown below:


 #define CONSTANTNAME value
 for example:
 #define VAT 0.15
 #define PI 3.14
 First comes #define, than the name followed by the value.

© Prof Suvendi Rimer, UJ


Summary: Data Types
 The basic data types associated with variables:
 int - integer: a whole number.
 long - integer: store a large whole number.
 float - floating point value: ie a number with a fractional part.
 double - a double-precision floating point value.
 char - a single character.
 void - valueless special purpose type .

© Prof Suvendi Rimer, UJ

You might also like