Variables and Data Types in C
Explained for Beginners
C programming is one of the most important foundational programming languages for beginners. Understanding variables and data types in C is essential to build strong programming logic. In this guide, we will clearly explain variables, data types, printf(), scanf(), and format specifiers with simple examples.
I have already explained the basic concepts of C, variables, data types, operators, input and output, and simple C programs in my previous blog in short. If you haven’t read that, I have added the link below. Please read that blog first and then read this one. It will be easier for you to understand.
A variable is like a container that stores data. Without variables, we cannot store or use data in a program.
Rules for Naming Variables in C
✔ Case-sensitive
Data Types in C
A data type tells the computer what kind of data we are storing.
1 int (Integer)
Used to store whole numbers.
Example:
This stores a whole number (no decimal).
2 float (Decimal Number)
Used to store numbers with decimal points.
Example:
This stores decimal value.
3 char (Character)
Used to store a single character.
Example:
Important: Characters are written inside single quotes.
4 double
Used to store large decimal numbers with more precision than float.
Example:
👉 double is more accurate than float.
5 long
Used to store very large whole numbers.
Example:
👉 When numbers are bigger than normal int, we use long.
6 short
Used to store small whole numbers.
Example:
👉 Uses less memory than int.
7 unsigned
Used when we don’t need negative numbers.
Example:
👉 Cannot store negative values.

cool
ReplyDeleteCool
ReplyDeleteHelpful
ReplyDeleteHelpful
ReplyDeleteGood
ReplyDeleteThankyou
ReplyDelete