2. A Data Type is a Type of Data.
Data types are the keywords, which are used for assigning a type to a
variable.
Data Type is a Data Storage Format that can contain a Specific Type or
Range of Values.
When computer programs store data in variables, each variable must be
assigned a specific data type.
In C, variable(data) should be declared before it can be used in program.
3. Whenever we declare variable in Computer’s memory, Computer must
know the type of the data to be stored inside the memory.
When the compiler encounters a declaration for a variable, it sets up a
memory location for it
If we need to store the single character then the size of memory occupied
will be different than storing the single integer number.
The memory in our computers is organized in bytes.
A byte is the minimum amount of memory that we can manage in C.
4. Syntax for declaration of a variable
data_type variable_name;
int var1;
int std_reg_no;
char std_gender;
5. • Built-in data types
– Fundamental data types (int, char, double, float, void, pointer)
– Derived data types (array, string, structure)
• Programmer-defined data types
– Structure
– Union
– Enumeration
6. Data Type keyword Description
Integer Data Type int Stores the Integer Value
Float Data Type float Stores the Floating Point Value
Character Data Type char Stores the Single Character Value
Long Data Type long Stores the Long range Integer Value
Double Data Type double Stores the long range Floating Value
7. Type Storage size Value range
char 1 byte -128 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned short 2 bytes 0 to 65,535
long 4 bytes -2,147,483,648 to 2,147,483,647
unsigned long 4 bytes 0 to 4,294,967,295
−
To
8. int - data type
int is used to define integer numbers.
float - data type
float is used to define floating point numbers.
char - data type
char defines characters.
int rollno;
rollno = 5;
float kilometre;
kilometre = 5.6;
char section;
section = ‘D';
9. double - data type
double is used to define BIG floating point numbers. It
reserves twice the storage for the number. On PCs this is
likely to be 8 bytes.
double Atoms;
Atoms = 2500000;
10. pointer-data type
A pointer is a special kind of variable designed for storing memory address i.e. the
address of another variable.
Declaring a pointer is the same as declaring a normal variable except you stick an
asterisk '*' in front of the variables identifier.
There are two new operators you will need to know to work with pointers.
The "address of" operator '&' and the "dereferencing" operator '*'.
When you place '&' in front of a variable you will get it's address, this can
be stored in a pointer vairable.
When you place an '*' in front of a pointer you will get the value at the
memory address pointed to.
11. {
int *ptr, q;
/* address of q is assigned to ptr */
ptr = &q;
/* display q’s value using ptr variable */
printf(“%d”, *ptr);
Output:
A0250
Example of pointer
12. An array is a collection of values, all of the same type, stored contiguously
in memory.
An array of size N is indexed by integers from 0 up to and including N-1.
There are also "arrays of unspecified size" where the number of elements
is not known by the compiler. Here is a brief
1.One dimensional array
2. Two dimensional array
array
15. To get the exact size of a type or a variable on a particular platform, you can use
the sizeof operator. The expressions sizeof(type) yields the storage size of the object or type in
bytes. Given below is an example to get the size of int type on any machine
#include<stdio.h>
#include<limits.h>
int main()
{
printf("Storage size for int : %d n", sizeof(int));
return 0;
}
sizeof(type)
16. Typecasting concept in C language is used to modify a variable from one date
type to another data type. New data type should be mentioned before the
variable name or value in brackets which to be typecast.
#include <stdio.h>
int main ()
{
float x;
x = (float) 7/5;
printf("%f",x);
}
Output: 1.400000
17. S.no Typecast function Description
1 atof() Converts string to float
2 atoi() Converts string to int
3 atol() Converts string to long
4 itoa() Converts int to string
5 ltoa() Converts long to string