Tutorial

Data Types and Modifiers in C

Published on August 3, 2022
Default avatar

By Pankaj

Data Types and Modifiers in C

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

Data Types In C
Data Types In C

Data Types in C

C has various data types to store data in program. C program can store integer, decimal number, character(alphabets), string(words or sentence), list etc. using various data types. We need to specify the data type of variable(identifier) to store any data in it. Explanation and basic usage of the concept is provided below. Data types and Modifiers have significant in-depth technical details which are not covered in this article. There are 2 categories of Data Types in C:

1. Primitive (Primary) Data Types

These data types store fundamental data used in the C programming.

  1. int It is used to store integer values. C program compiled with GCC compiler (32-Bit) can store integers from -2147483648 to 2147483647. The size of int is compiler dependent. It takes 4 bytes in a 32-bit compiler such as GCC.
int myIntegerValue = 100;
  1. char It stores single character such as ‘a’, ‘Z’, ‘@’ etc. including number, symbol or special character. It takes 1 byte (8-bits) to store each character.
char myCharacter = 'A';

Note: Every character has a corresponding ASCII value to it ranging from -128 to 127. Numbers as a character has their corresponding ASCII values too. For example, ‘1’ as char has ASCII value 49, ‘A’ has ASCII value 65.6. float It stores real numbers with precision upto 6 decimal places. It takes 4 bytes of memory and is also known as floating point number.

float myFloatingValue = 100.6543;
  1. double It stores real numbers with precision upto 15 decimal places. It takes 8 bytes of memory.
double myDoubleValue = 180.715586;

2. Derived and User Defined Data Types

These are made by collection or combination of primitive data types and hence known as derived data types. Details will be covered in the articles dedicated to each topic of the following:

  • Array
  • Structure
  • Union
  • Enum
  • Pointer

Modifiers in C

These are keywords in C to modify the default properties of int and char data types. There are 4 modifiers in C as follows.

Modifiers In C
Modifiers In C
  1. short It limits user to store small integer values from -32768 to 32767. It can be used only on int data type.
short int myShortIntegerValue = 18;
  1. long It allows user to stores very large number (something like 9 Million Trillion) from -9223372036854775808 to 9223372036854775807. Syntax “long long” is used instead of “long int”.
long long myLongIntegerValue = 827337203685421584;
  1. signed It is default modifier of int and char data type if no modifier is specified. It says that user can store negative and positive values.
signed int myNegativeIntegerValue = -544;
signed int mypositiveIntegerValue = 544;
/* Both of the statements have same meaning even without "signed" modifier*/
  1. unsigned When user intends to store only positive values in the given data type (int and char).
unsigned int myIntegerValue = 486;

Summary

It is important to understand the basic usage of data types to code and develop logic. There is a lot more about data types, however, you can easily proceed in your journey to C programming with the information provided.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors
Default avatar
Pankaj

author

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel