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

Lecture 3 SimpleDataTypes

This document discusses fundamental C data types. It explains that the basic units of memory are bits and bytes, with words being units of memory size dependent on the computer architecture. The main scalar data types are integers, floating point numbers, characters, and void. Integers can be short, int, long, and come in signed and unsigned varieties. Floating point types are float, double, and long double. Char stores a single character. Constants are fixed values defined using #define that cannot be altered during program execution.

Uploaded by

Tendani
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Lecture 3 SimpleDataTypes

This document discusses fundamental C data types. It explains that the basic units of memory are bits and bytes, with words being units of memory size dependent on the computer architecture. The main scalar data types are integers, floating point numbers, characters, and void. Integers can be short, int, long, and come in signed and unsigned varieties. Floating point types are float, double, and long double. Char stores a single character. Constants are fixed values defined using #define that cannot be altered during program execution.

Uploaded by

Tendani
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

C Programming: Simple Data Types

2
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.

3
❑ <type> <identifier> …
❑ Note Even though a type name may consist of more than one
word, it must still be considered as one autonomous type.
Fundamental C Data Types [2]
❑ The C language provides several fundamental data types.

4
5
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.

6
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
7
[unsigned] int Unsigned normal integer type
[signed] long [int] Signed long integer type
[unsigned] long [int] 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.

8
❑ 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.
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
semicolon 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.
9
❑ 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.
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 .

10

You might also like