TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

C Tutorials

C Basic Data types

Overview

The basic data types in the C language are used to hold one value at a time. These are also called primitive data types.

Basic Data types

The basic data types in C language are as follows:

  • char
  • bool
  • int
  • float
  • double

char

The char data type is used to hold single characters and occupies 1 byte of memory storage.

bool

A bool data type is used to store a boolean value. A boolean value can take one of two values: true or false. The bool data type requires 1 byte of memory.

int

An int data type is used to store whole numbers and cannot store fractional values with a decimal point.  There are two variations of this data type:

Short integer
Long integer

The short int requires 2 bytes of memory and the long int requires 4 bytes of memory. For example, we can declare the integers using the following keywords:

short int small_number;

long int large_number;

float

A float data type is used to store numbers that can have fractional values with the decimal point. These numbers are called floating point numbers. The float data type requires 4 bytes of memory.

double

A double data type is used to store floating point numbers with greater precision. The double data type requires 8 bytes of memory. We can use the double data type in calculations that requires greater precision.

Example

The sample demo C program illustrates the size of the data types occupied in the memory. The sizeof() operator is used to calculate the size of the data type. This operator returns the variable’s memory size in bytes.

 

#include<stdio.h>

/* **************************************************************
* Program Description: C Basic Data types
* Filename: datatypes.c
* C Tutorials - www.TestingDocs.com
*****************************************************************/

void main()
{
 // Declare variables of different data types
 char c;
 int i;
 float f;
 double d;


 // Print the memory size to hold the variables
 printf("Character data type size :: %d byte \n",sizeof(c));
 printf("Integer data type size :: %d bytes \n",sizeof(i));
 printf("Float data type size :: %d bytes \n",sizeof(f));
 printf("Double data type size :: %d bytes \n",sizeof(d));

}

 

C Basic Data Types

—

C Tutorials

C Programming Tutorials on this website:

https://www.testingdocs.com/c-language-tutorial/

Related Posts

C Language Characteristics

C Tutorials /

C Language Characteristics

C Source Code .c File

C Tutorials /

C Program Files & Formats

GNU Compiler Collection GCC

C Tutorials /

C Compilers

C Pointers

C Tutorials /

C Pointers

C Tutorials /

C Two-Dimensional Arrays

‹ Understanding a Simple C Program› C Program to get and display a number

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version