Data Types and Operators
(Non-Primitive Data Types)
Control Flow Statements
Conditional Statements
Looping Statements
Branching Statements
Object-Oriented Programming (OOP)
Exception Handling
Collections Framework
Overview of Collections
Java I/O
Multithreading
GUI Programming with Swing
Advanced Topics

In C, the fundamental data types are used to declare variables that can store different kinds of data. These types are essential for understanding how data is represented and manipulated in a C program. Below are the detailed descriptions of these data types.

'char'

  • Size: Typically 1 byte (8 bits).
  • Range: -128 to 127 (signed) or 0 to 255 (unsigned).
  • Usage: Used to store single characters or small integers. Also used in strings (arrays of characters).

Example:

				
					char letter = 'A';

				
			

'short'

  • Size: Typically 2 bytes (16 bits).
  • Range: -32,768 to 32,767 (signed) or 0 to 65,535 (unsigned).
  • Usage: Used to store small integers.

Example:

				
					short num = 1000;

				
			

'int'

  • Size: Typically 4 bytes (32 bits).
  • Range: -2,147,483,648 to 2,147,483,647 (signed) or 0 to 4,294,967,295 (unsigned).
  • Usage: Used to store integers.

Example:

				
					int count = 100000;

				
			

'long'

  • Size: Typically 8 bytes (64 bits).
  • Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (signed) or 0 to 18,446,744,073,709,551,615 (unsigned).
  • Usage: Used to store very large integers.

Example:

				
					long long veryLargeNum = 10000000000LL;

				
			

'float'

  • Size: Typically 4 bytes (32 bits).
  • Range: Approximately 1.2E-38 to 3.4E+38 (6-7 significant digits).
  • Usage: Used to store single-precision floating-point numbers.

Example:

				
					float pi = 3.14f;

				
			

'double'

  • Size: Typically 8 bytes (64 bits).
  • Range: Approximately 2.3E-308 to 1.7E+308 (15-16 significant digits).
  • Usage: Used to store double-precision floating-point numbers.

Example:

				
					double precisePi = 3.141592653589793;

				
			

'long double'

  • Size: Typically 10 bytes (80 bits) on x86 systems or 16 bytes (128 bits) on some others.
  • Range: Varies by implementation, but more precise and larger range than double.
  • Usage: Used to store extended-precision floating-point numbers.

Example:

				
					long double veryPrecisePi = 3.141592653589793238L;

				
			

'boolean (using _Bool or stdbool.h)'

  • Size: Typically 1 byte (though only 1 bit is needed).
  • Values: 0 (false) and 1 (true).
  • Usage: Used to store boolean values (true or false).

Example:

				
					#include <stdbool.h>

bool isTrue = true;

				
			

Size and Range Summary

TypeSize (bytes)Signed RangeUnsigned Range
char1-128 to 1270 to 255
short2-32,768 to 32,7670 to 65,535
int4-2,147,483,648 to 2,147,483,6470 to 4,294,967,295
long4 or 8At least -2,147,483,648 to 2,147,483,647At least 0 to 4,294,967,295
long long8-9,223,372,036,854,775,808 to 9,223,372,036,854,775,8070 to 18,446,744,073,709,551,615
float4~ 1.2E-38 to 3.4E+38N/A
double8~ 2.3E-308 to 1.7E+308N/A
long double10 or 16Varies by implementationN/A
bool (using _Bool or stdbool.h)10 (false) and 1 (true)N/A

Understanding these data types, their sizes, and ranges are crucial for writing efficient and error-free java programs. The specific size and range might vary slightly depending on the compiler and the architecture of the system.

Scroll to Top