0% found this document useful (0 votes)
25 views9 pages

Data Types and Qualifier

The document discusses fundamental data types in C including integer, floating point, and character types. It describes int, float, and double data types and their sizes. It also covers arrays, pointers, structures, and enumeration as derived data types. Qualifiers like long, short, signed, and unsigned are described which can alter the base data types.

Uploaded by

Uthoai Marma
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)
25 views9 pages

Data Types and Qualifier

The document discusses fundamental data types in C including integer, floating point, and character types. It describes int, float, and double data types and their sizes. It also covers arrays, pointers, structures, and enumeration as derived data types. Qualifiers like long, short, signed, and unsigned are described which can alter the base data types.

Uploaded by

Uthoai Marma
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/ 9

Data types in C

Fundamental Data Types


Integer types
Floating type
Character type

Derived Data Types


Arrays
Pointers
Structures
Enumeration
Integer data types
Integers are whole numbers that can have both positive and
negative values, but no decimal values.

Example: 0, -5, 10

In C programming, keyword int is used for declaring integer variable.

For example:

int id;
Here, id is a variable of type integer.

You can declare multiple variable at once in C programming.


For example:
int id, age;
The size of int is either 2 bytes(In older PC's) or 4 bytes.
If you consider an integer having size of 4 byte( equal to 32 bits), it
can take 232 distinct states as: -231,-231+1, ...,-2, -1, 0, 1, 2, ...,
231-2, 231-1

Similarly, int of 2 bytes, it can take 216 distinct states from -215 to
215-1. If you try to store larger number than 231-1,
i.e,+2147483647 and smaller number than -231, i.e, -2147483648,
program will not run correctly.
Floating types

Floating type variables can hold real numbers such as: 2.34, -9.382, 5.0
etc.

You can declare a floating point variable in C by using either float


or double keyword.

For example:
float accountBalance; double bookPrice;
Here, both accountBalance and bookPrice are floating type variables.

In C, floating values can be represented in exponential form as well.


For example:
float normalizationFactor = 22.442e2;
Difference between float and double

The size of float (single precision float data type) is 4 bytes. And the
size of double (double precision float data type) is 8 bytes. Floating
point variables has a precision of 6 digits whereas the precision of
double is 14 digits.

Character types

Keyword char is used for declaring character type variables. For


example:
char test = 'h'
Here, test is a character variable. The value of test is 'h'.
The size of character variable is 1 byte.
C Qualifiers

Qualifiers alters the meaning of base data types to yield a new data
type.
Size qualifiers
Size qualifiers alters the size of a basic type. There are two size
qualifiers, long and short. For example:

long double i;

The size of double is 8 bytes. However, when long keyword is used,


that variable becomes 10 bytes.
Sign qualifiers
Integers and floating point variables can hold both negative and
positive values. However, if a variable needs to hold positive value
only, unsigned data types are used.
For example:
// unsigned variables cannot hold negative value

unsigned int positiveInteger;

There is another qualifier signed which can hold both negative and
positive only. However, it is not necessary to define
variable signed since a variable is signed by default.
An integer variable of 4 bytes can hold data from -2 ^31 to 2^31-1.
However, if the variable is defined as unsigned, it can hold data from
0 to 2^32-1.
It is important to note that, sign qualifiers can be applied to int and
char types only.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy