Clouds
Home
Tutorial of C language
Computer Language
Introduction to C
Programming in C
Structure of C program
Variable in C
Datatypes in C
Token in C
Operator in C
Precedence of C Operator
Assignment Operator in C
Logical Operator in C
Bitwise Operator in C
Ternary Operator in C
C Input Output
Pointers in C
Storage Classes of C
Control Structure of C
C Decision Making Statement
C Looping Statement
C Jumping Statement
C Function
Function Call By Value
Function Call By Reference
C Input Output Function
C Structure
Array in C
Union in C

Datatypes in C

Data Types are means to identify the type of data and associated operations for handling it. There are three types of data types in C
  • Basic or Simple or Primitive data Types.
  • User-Defined Data Types
  • Derived Data Types

    Basic or Simple or Primitive data Types:

  • Basic data types are those that are not composed of other data types.
  • The primitive data types are also called basic data types or simple data types or fundamental data types.

    The various primitive data types of C language are classified as:

  • Integer (int)
  • Character (char)
  • Floating Point loat)
  • Double precision (double)
  • Empty Data type (void)

    Integer Data Type:

  • int is used to define integer numbers.
  • It is keyword which is used to define integer number. Normally they are associated with the variables to store signed integer values in memory locations. i.e using this data types positive and negative numbers can be stored in the memory.
    Data type Size (Bytes)Range
    Signed int 2-32768 to +32767
    Unsigned int2 0 to 65535
    Example:-
    				void  main()
    				{
    					clrscr();
    				 	int a;
    				 	a= 5;
    					printf("%d",a);
    					getch();
    				}
    				

    Character Data Type:

    A single character can defined as a character type data. Characters in "C" are declared by the keyword "char". It is stored in 1 byte of internal storage. The qualifier signed or unsigned may be explicitly applied to char while unsigned characters have values between 0 to 255. Signed char have values from -128 to 127.
    Data type Size (Bytes)Range
    Signed int 1-128 to +127
    Unsigned int1 0 to 255
    Example:-
    				void main()
    				{
    				  	char x;
    				  	x= 'A';
    				  	printf("%c",x);
    				  	getch();
    				}
    				

    Float Data Type:

  • Float is used to define floating point numbers. Floating point numbers are stored in 4 bytes with 6 bits of precision. Floating point numbers in "C" are defined by the keyword "float". When the accuracy provided by a float number is not sufficient, the type "double" can be used to define the number which uses 8 bytes with a precision of 10 digits. It is also known as double precision numbers.
    Data type Size (Bytes)Range
    Float 4-3.4e38 to +3.4e38
    Example:-
    				#include<stdio.h>
    				#include<conio.h>
    				void main()
    				{
    					float  a;
    					clrscr();
    					a = 5.6;
    					printf("%f",a);
    				    getch();
    				}
    				

    Example:-
    				void  main()
    				{
    					int  a=5;
    					float  b=5.5;
    					char  x=A;
    					printf("%d",a);
    					printf("%f",b);
    					printf("%c",x);
    					getch();
    				}
    				

    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. Example:-
    				void main()
    				{
    					clrscr();
    					double a;
    					a= 2500000;
    					printf("%d",a);
    					getch();
    				}
    				

    Write a program to check size of memory taken by various datatypes.


    				#include<stdio.h>
    				#include<conio.h>
    				void  main()
    				{
    					clrscr();
    				  	printf("sizeof(char) == %d\n", sizeof(char));
    				  	printf("sizeof(short) == %d\n", sizeof(short));
    				  	printf("sizeof(int) == %d\n", sizeof(int));
    				  	printf("sizeof(long) == %d\n", sizeof(long));
    				  	printf("sizeofloat) == %d\n", sizeofloat));
    				  	printf("sizeof(double) == %d\n", sizeof(double));
    				  	printf("sizeof(long double) == %d\n", sizeof(long double));
    				  	printf("sizeof(long long) == %d\n", sizeof(long long));
    					getch();
    				}
    				

    User Defined Data Types

  • "C" supports a feature known as "type definition" that allows user to define an identifier that would represent an existing data type. The user defined data type identifier can later be used to declare variables. It takes the general form as:
  • A Special data type that is defined by user from the derived data type is called user-defined data type or user-defined derived data typs.
    Example:
  • Structure
  • Union
  • Enumeration

    Derived Data Types

    Derived data types are built from the fundamental (Basic) data type. Following are the example of Derived data types.
  • Array
  • Function
  • Pointer
    Token in C >>
    Operator in C >>
    Precedence of C Operator >>
    Assignment Operator in C >>
    Logical Operator in C >>


    Home Clouds