C Programming • C Basics, Operators, Loops
C Programming / Data types

Data types

Notes 2 C Basics, Operators, Loops

A data type tells the compiler what kind of data a variable can store. It also determines the type of value that can be stored and the operations that can be performed on it.

Notes

Data Types in C

A data type tells the compiler what kind of data a variable can store. It also determines the type of value that can be stored and the operations that can be performed on it.

💡 In Simple Words

A data type tells C whether a variable will store a number, character, decimal value, or another type of data.

Real-World Example

🌍 Example

Think about a student record: Age can be an integer, Percentage can contain decimal values, and Grade can be a character. Different types of data need different data types.

Basic Data Types in C

Data Type Used For Example
int Integer numbers 25, -10
char A single character 'A', '5'
float Decimal numbers 3.14
double Decimal numbers with higher precision 12.345678
void Indicates no value or no return value void function()

1. int

The int data type is used to store whole numbers without a fractional part.

💡 Example

int age = 20;

2. char

The char data type is used to store a single character. Character values are written inside single quotation marks.

💡 Example

char grade = 'A';

3. float

The float data type is used to store numbers that contain a decimal or fractional part.

💡 Example

float percentage = 82.5;

4. double

The double data type is used for floating-point values when more precision is required than a typical float.

💡 Example

double pi = 3.1415926535;

5. void

The void type represents the absence of a value. It is commonly used with functions that do not return a value.

💡 Example

void display()

Example: Using Different Data Types

int age = 20; char grade = 'A'; float percentage = 82.5; double pi = 3.1415926535;

Why Are Data Types Important?

  • They tell the compiler what kind of data a variable stores.
  • They help the compiler allocate suitable memory for data.
  • They determine which operations are appropriate for the data.
  • They help prevent incorrect use of values.

Data Type and Variable

A variable is declared by writing its data type followed by the variable name.

DATA TYPE + VARIABLE NAME + VALUE ↓ int age = 20;

Quick Revision

Type Remember
int Whole numbers
char Single character
float Decimal values
double Decimal values with higher precision
void No value / no return value

Important Exam Questions

Short Answer Questions

  1. What is a data type in C?
  2. Why are data types used in C?
  3. What is the use of int?
  4. What is the use of char?
  5. What is the difference between float and double?
  6. What is the use of void?
  7. Write any five basic data types in C.

Long Answer Questions

  1. Define data types and explain the basic data types in C with examples.
  2. Explain int, char, float, double and void with suitable examples.
  3. Explain why data types are important in C programming.
🎥 Recommended Learning

Watch a beginner-friendly explanation of basic data types in C.

▶ Watch: Data Types in C — Hindi

📝 Handwritten Notes

A short handwritten-style revision sheet for C data types will be provided here.

🧠 Mind Map

Use the mind map for quick revision of basic C data types.