0% found this document useful (0 votes)
22 views3 pages

Data Type Modifiers in C

Uploaded by

Illegal school
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)
22 views3 pages

Data Type Modifiers in C

Uploaded by

Illegal school
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/ 3

Data Type Modifiers and Format Specifiers in C

Introduction

In C programming, data type modifiers are used to alter the storage size or range of the base data types.

They are typically used with integer types to control memory and value range.

Data Type Modifiers Table

List of Data Type Modifiers in C:

| Modifier | Used With | Description |

|--------------|----------------|--------------------------------------------------------------|

| signed | int, char | Allows both positive and negative values (default for int) |

| unsigned | int, char | Only allows non-negative values (0 and up) |

| short | int | Reduces the size (usually 2 bytes) |

| long | int, double | Increases the size (usually 4 or 8 bytes) |

| long long | int | Even larger size (usually 8 bytes) |

Example Usage

Example Usages:

signed int a = -10;

unsigned int b = 20;

short int c = 32767;

long int d = 100000L;

long long int e = 10000000000LL;

unsigned char f = 255;

Size and Range of Data Types


Data Type Modifiers and Format Specifiers in C

Size and Range (Typical for 32-bit System):

| Type | Size (bytes) | Range |

|--------------------|--------------|--------------------------------|

| short int |2 | -32,768 to 32,767 |

| unsigned short |2 | 0 to 65,535 |

| int |4 | -2,147,483,648 to 2,147,483,647|

| unsigned int |4 | 0 to 4,294,967,295 |

| long int | 4 or 8 | Larger range |

| long long int |8 | Very large range |

| unsigned long | 4 or 8 | Larger positive only |

Format Specifiers Table

Format Specifiers for Modified Data Types:

| Data Type Modifier | Data Type | Format Specifier | Example Usage |

|---------------------|------------------|------------------|----------------------------|

| short int | signed | %hd | printf("%hd", a); |

| short int | unsigned | %hu | printf("%hu", b); |

| int | signed (default) | %d or %i | printf("%d", c); |

| int | unsigned | %u | printf("%u", d); |

| long int | signed | %ld | printf("%ld", e); |

| long int | unsigned | %lu | printf("%lu", f); |

| long long int | signed | %lld | printf("%lld", g); |

| long long int | unsigned | %llu | printf("%llu", h); |

| char | signed/unsigned | %c | printf("%c", ch); |

| unsigned char | | %hhu | printf("%hhu", uc); |

| float | | %f | printf("%f", x); |


Data Type Modifiers and Format Specifiers in C

| double | | %lf | printf("%lf", y); |

| long double | | %Lf | printf("%Lf", z); |

Note on scanf()

For scanf(), use the same specifiers but with pointer variables:

Example:

int a;

scanf("%d", &a);

Sample Program

Example Program:

#include <stdio.h>

int main() {

short int si = 1000;

unsigned int ui = 40000;

long long int lli = 1234567890123;

printf("Short int: %hd\n", si);

printf("Unsigned int: %u\n", ui);

printf("Long long int: %lld\n", lli);

return 0;

You might also like