R4R
Right Place For Right Person TM
 
R4R CC TutorialsC Basic Tutorials1.3Data Types
previous

Home

Next

Data types:-
Primary data type, Integer Type, Floating Point Types, Void type, Character Type, Size and Range of Data Types on 16 bit machine, derived data type, Declaration of Variables, User defined type declaration, Declaration of Storage Class, auto, static, extern, and register, Defining Symbolic Constants, Declaring Variable as Constant and Volatile Variable

C language data types can be classified as
Primary data type
Derived data type
User-defined data type


Primary data type
All C Compilers accept the following fundamental data types

 

1.

 

Integer

 

int

 

2.

 

Character

 

char

 

3.

 

Floating Point

 

float

 

4.

 

Double precision floating point

 

double

 

5.

 

Void

 

void

 


The size and range of each data type is given in the table below

 

DATA TYPE

 

RANGE OF VALUES

 

char

 

-128 to 127

 

Int

 

-32768 to +32767

 

float

 

3.4 e-38 to 3.4 e+38

 

double

 

1.7 e-308 to 1.7 e+308

 

 

Integer Type :
Integers are whole numbers with a machine dependent range of values. A good programming language as to support the programmer by giving a control on a range of numbers and storage space. C has 3 classes of integer storage namely short int, int and long int. All of these data types have signed and unsigned forms. A short int requires half the space than normal integer values. Unsigned numbers are always positive and consume all the bits for the magnitude of the number. The long and unsigned integers are used to declare a longer range of values.

Floating Point Types :
Floating point number represents a real number with 6 digits precision. Floating point numbers are denoted by the keyword float. When the accuracy of the floating point number is insufficient, we can use the double to define the number. The double is same as float but with longer precision. To extend the precision further we can use long double which consumes 80 bits of memory space.

Void Type :
Using void data type, we can specify the type of a function. It is a good practice to avoid functions that does not return any values to the calling function.

Character Type :
A single character can be defined as a defined as a character type of data. Characters are usually stored in 8 bits of internal storage. The qualifier signed or unsigned can be explicitly applied to char. While unsigned characters have values between 0 and 255, signed characters have values from –128 to 127.

Size and Range of Data Types on 16 bit machine.
 

TYPE

 

SIZE (Bits)

 

Range

 

Char or Signed Char

 

8

 

-128 to 127

 

Unsigned Char

 

8

 

0 to 255

 

Int or Signed int

 

16

 

-32768 to 32767

 

Unsigned int

 

16

 

0 to 65535

 

Short int or Signed short int

 

8

 

-128 to 127

 

Unsigned short int

 

8

 

0 to 255

 

Long int or signed long int

 

32

 

-2147483648 to 2147483647

 

Unsigned long int

 

32

 

0 to 4294967295

 

Float

 

32

 

3.4 e-38 to 3.4 e+38

 

Double

 

64

 

1.7e-308 to 1.7e+308

 

Long Double

 

80

 

3.4 e-4932 to 3.4 e+4932

 

 

Non-Primitive Data Type:-
A non-primitive data type is am abstract data type that is built out of primitive data types - linked list, queue, stack, etc.

Declaration of Variables
Every variable used in the program should be declared to the compiler. The declaration does two things.

1. Tells the compiler the variables name.
2. Specifies what type of data the variable will hold.


Example:
Int sum;
Int number, salary;
Double average

Datatype

Keyword Equivalent

 

Character

 

char

 

Unsigned Character

 

unsigned char

 

Signed Character

 

signed char

 

Signed Integer

 

signed int (or) int

 

Signed Short Integer

 

signed short int (or) short int (or) short

 

Signed Long Integer

 

signed long int (or) long int (or) long

 

UnSigned Integer

 

unsigned int (or) unsigned

 

UnSigned Short Integer

 

unsigned short int (or) unsigned short

 

UnSigned Long Integer

 

unsigned long int (or) unsigned long

 

Floating Point

 

float

 

Double Precision Floating Point

 

double

 

Extended Double Precision Floating Point

 

long double

 

 


User defined type declaration:-
In C language a user can define an identifier that represents an existing data type. The user defined datatype identifier can later be used to declare variables. The general syntax is typedef type identifier;>

here type represents existing data type and ‘identifier’ refers to the ‘row’ name given to the data type.
Example:
typedef int salary;

typedef float average;

Here salary symbolizes int and average symbolizes float. They can be later used to declare variables as follows:

Units dept1, dept2;
Average section1, section2;


Therefore dept1 and dept2 are indirectly declared as integer datatype and section1 and section2 are indirectly float data type.

The second type of user defined datatype is enumerated data type which is defined as follows.


Enum identifier {value1, value2 …. Value n};

The identifier is a user defined enumerated datatype which can be used to declare variables that have one of the values enclosed within the braces. After the definition we can declare variables to be of this ‘new’ type as below.

enum identifier V1, V2, V3, ……… Vn

The enumerated variables V1, V2, ….. Vn can have only one of the values value1, value2 ….. value n

Example: enum day {Monday, Tuesday, …. Sunday};

enum day week_st, week end;

week_st = Monday;

 week_end = Friday;

 if(wk_st == Tuesday) week_en = Saturday;

 

previous

Home

Next

R4R CC TutorialsC Basic Tutorials1.3Data Types
Tolal:0 Click:
Show All Comments

Post Your Comments

Your Name:

Your Email ID :
Comments :
URL
  =* Enter SUM

New Updates

10:New Updates
Tutorials,examples and Interview Questions with answers
Posted By: Shashi     Posted Date:02.10.14

9:C# Tutorials,C# examples and C# Interview Questions with answers
R4R provide C# Tutorials,C# examples and C# Interview Questions with answers. Through R4R you can develop a small application and small programs.We cover C# Tutorials,C# examples and C# Interview Questions and answers for freshers as well experienced programmer.
Posted By: Shashi     Posted Date:11.17.13

8:Java/J2EE(Servlet,JSP,JNDI,Struts,Spring,Hibernate,EJB,JSF,JMS,Web-Services)
In this section R4R covers Java/J2EE(Servlet,JSP, JNDI, Struts, Spring, Hibernate, EJB,JSF,JMS,Web-Services) Tutorials with Examples.R4R provide Java/J2EE (Servlet,JSP, JNDI,Struts, Spring, Hibernate, EJB, JSF, JMS, Web-Services) Interview Questions with answers study materials for freshers and experienced.
Posted By: Shashi     Posted Date:11.13.13

7:CoreJava Tutorials , CoreJava Examples and CoreJava Interview Questions with answers
In this section R4R covers CoreJava Tutorials with CoreJava Examples. R4R covers CoreJava programming concept in easy way. R4R provide CoreJava Interview Questions with answers study materials for freshers and experienced.
Posted By: Shashi     Posted Date:11.04.13

6:Microsoft.net Technology ASP.NET,c# ,ADO.NET,WCF,WPF,Silverlight ,VB.net
R4R provides Microsoft Technologies(like ASP.NET,c# ,ADO.NET,WCF,WPF, Silverlight and VB.ne)Tutorials with Examples,programming concept and Interview Questions with answers study materials for freshers and experienced.
Posted By: Shashi     Posted Date:11.04.13

5:J2me Tutorials concept with Examples with Netbean IDE and J2ME Application Examples.
R4R cover basic J2me Tutorials concept with Examples and provide a way to develop J2me programming concept in easy way. R4R provide J2me Interview Questions with answers.R4R provide J2me Languages study materials with examples uing Netbean IDE and J2ME Application Examples.
Posted By: Shashi     Posted Date:10.30.13

4:J2me Tutorials concept with Examples ith netbean IDE and J2ME Application Examples.
R4R cover basic J2me Tutorials concept with Examples and provide a way to develop J2me programming concept in easy way. R4R provide J2me Interview Questions with answers.R4R provide J2me Languages study materials with examples uing Netbean IDE and J2ME Application Examples.
Posted By: Shashi     Posted Date:10.30.13

3:Java ebooks , Java tutorials , Java examples , Java interview questions and answers
R4R provides study materials for Java/j2EE technologies. R4R covers core java, advanced java, servlet, JSP, Struts, Spring, Hibernate, EJB, JSF, J2ME, ANT, JUnit and Some APIS .R4R also provides ebooks,tutorials,examples, interview questions and answers.
Posted By: Shashi     Posted Date:10.30.13

2:Learn basic C++ Tutorials with Examples , C++ Interview Questions with answers
R4R is a free E-learning website.You can learn basic C++ Tutorials with Examples , C++ Interview Questions with answers and also some hot topics.
Posted By: Shashi     Posted Date:10.30.13

1:C Tutorials with Example C subjective and objective interview questions and answers
R4R provide C Tutorials with Example and also provides C subjective and objective interview questions and answers.You can learn C in easy way.We cover basics of C here and give some examples.
Posted By: Shashi     Posted Date:10.30.13

R4R
R4R
R4R
R4R
R4R
R4R
R4R
R4R