Curriculum
Course: C basic
Login

Curriculum

C basic

C Introduction

0/1

C Get Started

0/1

C Comments

0/1

C Constants

0/1

C Operators

0/1

C Break and Continue

0/1

C User Input

0/1

C Memory Address

0/1

C Structures

0/1
Text lesson

Data Types

Data Types

In C, as outlined in the Variables section, each variable must have a defined data type. Additionally, when displaying variables using the printf() function, it’s necessary to include a format specifier.

Example

// Create variables
int myNum = 5;             // Integer (whole number)
float myFloatNum = 5.99;   // Floating point number
char myLetter = ‘D’;       // Character

// Print variables
printf(“%d\n”, myNum);
printf(“%f\n”, myFloatNum);
printf(“%c\n”, myLetter); 

Basic Data Types

The data type determines the size and nature of the information stored in a variable.

This tutorial will primarily cover fundamental data types.

Data Type

Size

Description

Example

Int

2 or 4 bytes

Stores integers, excluding decimals.

1

Float

4 bytes

Stores floating-point numbers, which include one or more decimals. Can accommodate approximately 6-7 decimal digits.

1.99

Double

 8 bytes

Stores floating-point numbers, which include one or more decimals. Can accommodate approximately 15 decimal digits.

1.99

char

1 byte

Stores a single character, letter, number, or ASCII value.

'A'

Basic Format Specifiers

Various data types have distinct format specifiers associated with them. Here are a few examples:

Format Specifier

Data Type

%d or %i

Int

%f or %F

Float

%lf

Double

%c

Char

%s

Reserved for strings (text), details of which will be covered in a subsequent chapter.