Tutorials  /  Linux Basics

Understanding Data Types in C: A Comprehensive Guide

Ccentron Redaktion · February 2025 ·5 min read ·Linux Basics, Tutorial

When writing programs in C, one of the most fundamental concepts you will encounter is data types. Data types allow you to store different kinds of data such as integers, decimal numbers, characters, strings, and more. To store any data in a variable, you must specify its data type. This blog post will provide an overview of the essential data types in C and explain how they can be used in your programs. Although this guide doesn't cover the more in-depth technical details, it will introduce you to the most commonly used data types in C and their modifiers.

Categories of Data Types in C

C divides data types into two main categories:

  1. Primitive (Primary) Data Types
  2. Derived and User-Defined Data Types

Let's explore both categories in detail.

1. Primitive (Primary) Data Types

Primitive data types in C are the most basic types, used to store fundamental data. These include:

Integer (`int`)

The int type is used to store integer values, both positive and negative. The range of values depends on the compiler, but in a 32-bit GCC compiler, you can store integers from -2,147,483,648 to 2,147,483,647. The int type takes up 4 bytes of memory.

Code
int myIntegerValue = 100;

Character (`char`)

The char type stores single characters, which could be letters, numbers, symbols, or special characters. Each char occupies 1 byte (8 bits) of memory. Every character also has a corresponding ASCII value; for example, 'A' has an ASCII value of 65, while '1' has an ASCII value of 49.

Code
char myCharacter = 'A';

Floating Point (`float`)

The float type stores real numbers with precision up to 6 decimal places. It requires 4 bytes of memory. This data type is useful for storing values such as 3.14159 (π).

Code
float myFloatingValue = 100.6543;

Double Precision Floating Point (`double`)

The double type is used for storing real numbers with even greater precision—up to 15 decimal places. A double takes up 8 bytes of memory, making it suitable for calculations requiring high precision.

Code
double myDoubleValue = 180.715586;

2. Derived and User-Defined Data Types

Derived data types are created by combining primitive data types, and they include:

  • Array
  • Structure
  • Union
  • Enum
  • Pointer

These advanced types allow for more complex data handling. Although this blog doesn't cover them in detail, each of these topics deserves a deeper dive in future articles.

Modifiers in C

Modifiers in C allow you to change the default properties of int and char data types. There are four primary modifiers in C:

Short

The short modifier limits the storage of small integer values, ranging from -32,768 to 32,767. It can only be applied to int data types.

Code
short int myShortIntegerValue = 18;

Long

The long modifier allows you to store very large numbers, ranging from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. The syntax long long is used for even larger values.

Code
long long myLongIntegerValue = 827337203685421584;

Signed

By default, the signed modifier is applied to both int and char data types. This means that the variable can hold both negative and positive values.

Code
signed int myNegativeIntegerValue = -544;
signed int myPositiveIntegerValue = 544;

Both of the above declarations work even if you omit the signed modifier, as it is implied.

Unsigned

When you need to store only positive values, you can use the unsigned modifier. This is particularly useful for int and char data types.

Code
unsigned int myIntegerValue = 486;
VM

Matching infrastructure at centron

No hardware needed to follow along: ccloud³ VMs with full root access start at €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Conclusion

Having a solid understanding of data types is critical for writing efficient and logical C programs. This guide covered the basic types of data used in C, including integer, character, floating-point, and double-precision types, along with the role of modifiers. There is much more to explore in terms of data types, but with this knowledge, you are now ready to continue your journey in C programming.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Linux Basics
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren