0% found this document useful (0 votes)
18 views7 pages

C Fundamental Part3

C classroom notes

Uploaded by

Himanshu Narayan
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)
18 views7 pages

C Fundamental Part3

C classroom notes

Uploaded by

Himanshu Narayan
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/ 7

C Programming Notes-Fundamentals (Part III)

Data Types

Data types define the type of data that a variable can hold.
C provides several data types to handle various kinds of data, such as
integers, floating-point numbers, and characters etc.

Data type category:


 Primitive Data Types (Basic Data Types/ Built-in Data Types)
 Non-Primitive Data Types (Derived Data Types)
 User-Defined Data Types (created by User)

Primitive data types are the fundamental data types provided by the C
language. They are used to represent simple values like integers,
floating-point numbers, characters and void.

Non-primitive data types are derived from primitive data types. These
data types can hold multiple values like array, pointer, structure, union
etc.

User-defined data types are created by user/programmer to define new


types that are built from existing data types like enum, typedef etc.

© HIMANSHU NARAYAN PRASAD, VVIT 1


C Programming Notes-Fundamentals (Part III)

i. int :
it is used to represent integer numbers(whole number) (+ve or -ve).
There are some variants of int data type like long, long long , etc.

List of integer data type and its variants

 unsigned is used to represent 0 to +ve value while signed


represents -ve to +ve value.

We can use sizeof() operator to find size of data types as-

Type casting by User (data type conversion)

© HIMANSHU NARAYAN PRASAD, VVIT 2


C Programming Notes-Fundamentals (Part III)

Output:

ii. float/double:

The concept of floating-point numbers dates back to the early days of


computing.
Early computers often used fixed-point arithmetic, where the decimal
point was assumed to be in a fixed position within the number. This
limitation made it difficult to represent a wide range of values.
To address this, floating-point arithmetic was developed.
The IEEE 754 standard, introduced in 1985, standardized floating-point
formats and operations.

C provides two primary floating-point types:


 float: Single-precision floating-point number(precision of around 7
decimal digits)
 double: Double-precision floating-point number, providing greater
precision(precision of around 15-16 decimal digits)

Float contains 3 elements:


 Sign Bit: Indicates whether the number is positive or negative.
 Exponent: Determines the magnitude of the number.
 Mantissa: Represents the significant digits of the number.

© HIMANSHU NARAYAN PRASAD, VVIT 3


C Programming Notes-Fundamentals (Part III)

Representation of float/double-

© HIMANSHU NARAYAN PRASAD, VVIT 4


C Programming Notes-Fundamentals (Part III)

It is always signed, meaning it can hold both positive and negative values
The reason float cannot be unsigned in C is due to the nature of real
numbers.
Real numbers, unlike integers, can be positive, negative, or zero.
To represent this full range of values accurately, a floating-point number
needs a sign bit to distinguish between positive and negative values.

List of float data type and its variants

Example:

© HIMANSHU NARAYAN PRASAD, VVIT 5


C Programming Notes-Fundamentals (Part III)

iii. char:
Characters in C are used to represent individual symbols, such as letters,
digits, punctuation marks, and special characters.
They are typically stored as a single byte (8 bits) .
It can represent both signed and unsigned characters.

Character literals are represented in single quote ‘ ‘

C allows to store multiple characters in a character array, also known as


a string.
Each character in the array is terminated by a null character ’ \0’.

In above example, the str array contains 13 characters:


'H' 'e' 'l' 'l' 'o' ',' '' 'w' 'o' 'r' 'l' 'd'
'\0'

The null character at the end indicates the end of the string.

© HIMANSHU NARAYAN PRASAD, VVIT 6


C Programming Notes-Fundamentals (Part III)

List of char data type and its variants

Example:

In above code, %c gives chracter ‘5’ ,%d gives ASCII value(integer) of ‘A’.

© HIMANSHU NARAYAN PRASAD, VVIT 7

You might also like