Top Banner
15

Datatypes

Aug 07, 2015

Download

Education

Ram Sandeep
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Datatypes
Page 2: Datatypes

DATATYPES

BASIC DATATYPES

DERIVED DATATYPES

USER DEFINED DATATYPES

VOID

Page 3: Datatypes

2.BASIC DATATYPESint float

chardouble

Page 4: Datatypes

Example :-When customer goes to a fruit vendor….

Page 5: Datatypes

Need of Datatypes in programming

vendor: what do u want sir/madam.Customer: I want apple. How much does it costs?

Vendor: How many do u want sir/madam.Customer : Answers according to his/her requirement.which is

a variable x( which changes every time).Vendor : Now he calculates the rate(c.p + profit) and sells the

apples.In order to do this calculation in programming we need a thing

that can hold a value (a number like 5 or 20 etc)That’s where we need Datatypes

Page 6: Datatypes

Variable and constant

Page 7: Datatypes

Syntax of Datatypes in C

In the example:

• Number of apple he /she wanted. <value>• Customer asked for apples. That identifies what he wants. <identifier name>• To store this value we need a box in programming which is a type integer in

C<type>Format for Datatypes declaration and definition is :<type> <identifier name>=<value>Ex:Int apples =20;

Page 8: Datatypes

Types of Datatypes Datatype Use to hold Example

int for integer range numbers -5

float for decimal range numbers 99.99

char for character numbers A

double for more precision decimal numbers 99.999999

* Long <datatype> for hold big numbers 34,333

* short <datatype> for value inside 32,768 8987

signed <datatype> **for only positive numbers 88

Unsigned<datatype> **for positive and negative numbers -96

•Except char Datatype.•In char we have -128 t0 127 range for unsigned char and 0 to 255 for signed char

Page 9: Datatypes

Sizeof

This will give u the size(int value) of the variable.Syntax:- sizeof(<identifier name>);

Example:-int a,b;b=sizeof(a);

Page 10: Datatypes

Table of DatatypesType *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

*Size depends on how many bit processor u r running on

Page 11: Datatypes

Types of Datatypes(cont..)

Type Storage size Value range Precision

float 4 byte 1.2E-38 to 3.4E+38 6 decimal places

double 8 byte 2.3E-308 to 1.7E+308 15 decimal places

long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places

Page 12: Datatypes

Printf advance…

Syntax:-Printf(“<format string>”,<list of arguments>);Format string:-• %c char single character• %d (%i) int signed integer• %e (%E) float or double exponential format• %f float or double signed decimal• %g (%G) float or double use %f or %e as required• %o int unsigned octal value• %p pointer address stored in pointer• %s array of char sequence of characters• %u int unsigned decimal• %x (%X) int unsigned hex value

Example:Printf(“text %d”,apples);

Page 13: Datatypes
Page 14: Datatypes
Page 15: Datatypes

Additional links

Website:-http://Sandeepedu65.blogspot.inYoutube :-https://www.youtube.com/watch?v=_t0L462p930

Contact me:-Email id:[email protected]