0% found this document useful (0 votes)
275 views3 pages

Variables and Data Types - C

A variable is a container that stores a value of a specified data type. Variables must be declared with a data type and can then be initialized with a value. Common data types in C include basic types like int, char, float, and double, as well as derived types like arrays, pointers, structures, unions, enums, and void. Each data type specifies the size and range of values a variable can store, such as int being 2 bytes and ranging from -32,768 to 32,767. Proper naming of variables follows rules like only using alphanumeric characters and underscores and not starting with digits.

Uploaded by

adityakmcs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
275 views3 pages

Variables and Data Types - C

A variable is a container that stores a value of a specified data type. Variables must be declared with a data type and can then be initialized with a value. Common data types in C include basic types like int, char, float, and double, as well as derived types like arrays, pointers, structures, unions, enums, and void. Each data type specifies the size and range of values a variable can store, such as int being 2 bytes and ranging from -32,768 to 32,767. Proper naming of variables follows rules like only using alphanumeric characters and underscores and not starting with digits.

Uploaded by

adityakmcs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

1

VARIABLES AND DATA TYPES

Q. What is a Variable?
In Simple Language: -

A variable is a Container that stores a value that value can be any type like characters, decimal numbers,
floating numbers etc. And these values can be changed during the execution of the program.

Example:
int var_name = 5 ;

Data Type Variable Name Value Stored in Variable


Ex. 1.1

➢ A name given to the memory location.


➢ Declared by writing type variable_name;
➢ Initialized and declared by type variable_name = value; as given in example.
➢ Declaration means Reserving a location in memory for a variable.
Example:
int var_name, var_name2, a, s;

➢ Initialization means assigning a value after declaration of variable as example in Ex. 1.1.

Rules for defining variables: -

1. A variable can have alphabets, digits, and underscore.


2. A variable name can start with the alphabet, and underscore only. It can’t start with a digit.
3. No whitespace is allowed within the variable name.
4. A variable name must not be any reserved word or keyword, e.g., int, goto, etc.
▪ Valid variable names: int ady, char aditya_shahi, float _aditya1233
▪ Invalid variables name: int @aditya, int 12aditya, char long

Q. What is Data Types?

Data types simply refers to the type and size of data associated with variables.
OR
A data type specifies the type of data that a variable can store such as integer, floating, character etc. Data
types in C.

DATA TYPES IN C: -
➢ Basic Data Types: int, char, float, double
➢ Derived Data Types: array, pointer, structures, union
➢ Enumeration data Type: enum
➢ Void Data Type: void (means Empty)

By Aditya Shahi
2

Data Types Memory Size Range Format


Specifier

char 1 byte −128 to 127 %c

signed char 1 byte −128 to 127 %c

unsigned char 1 byte 0 to 255 %c

int 2 bytes −32,768 to 32,767 %d

unsigned int 2 bytes 0 to 65,535 %u

short int 2 bytes −32,768 to 32,767 %hd

signed short int 2 bytes −32,768 to 32,767 %hi

unsigned short int 2 bytes 0 to 65,535 %hu

long int 4 bytes -2,147,483,648 to 2,147,483,647 %ld

Long long int 8 bytes -(2^63) to (2^63)-1 %lld

Unsigned long long int 8 bytes 0 to 18,446,774,073,709,551,615 %llu

unsigned long int 4 bytes 0 to 4,294,967,295 %lu

float 4 bytes %f

double 8 bytes %lf

long double 10 bytes %Lf

By Aditya Shahi
3

By Aditya Shahi

You might also like