Variable declaration

21
ARVIN santos buendia

description

for 4th quarter computer LT review

Transcript of Variable declaration

Page 1: Variable declaration

ARVINsantosbuendia

Page 2: Variable declaration

OBJECTIVES

1. Discuss the different data types that can be used in Turbo-C

2. Explain and evaluate the rules in naming variables

3. Create the syntax of data types and variable names in Turbo-C Codes

Page 3: Variable declaration

VARIABLE DECLARATION OF TURBO-C

SYNTAX

<data type> <variable name>

char g;

int x, y, z;

float f=5.67;

int x=10;

char name[10];

Page 4: Variable declaration

< DATA TYPES >int a whole number consisting of

an optional sign (+ or -) followed

by a sequence of digit

can hold integer quantities

that do not require a fractional

component or decimal places

occupies two bytes in the

address

ranges from –32768 to +32767

Page 5: Variable declaration

< DATA TYPES > Types of int1. long int

takes up more space and can

store large number

ranges from –2147483648 to

+2147483647

occupies 4 bytes

2.unsigned int

cannot be negative from 0 to

65536

Page 6: Variable declaration

< DATA TYPES >

float consists of an optional sign (+ or -),

followed by one or more digits , a

decimal point, and one or more further

digits

it can include an optional exponent

ranging from 3.4 E –38 to 3.4 E +38 

Page 7: Variable declaration

< DATA TYPES >

double is a special float which can store

more significant digits and have longer

exponent

ranges from 1.7E-308 to 1.7E+308

with 15 digits accuracy

Page 8: Variable declaration

< DATA TYPES >

char can be used to contain a single

letter, digit, punctuation mark or control

symbol recognized by the computer

written enclosed within single

quotation marks, but literals strings are

enclosed in double quotation marks

Page 9: Variable declaration

< DATA TYPES >

char a character may be assigned an

integer value between –128 and +127

unsigned char data type may be

assigned an integer value from 0 to

255char c;char b = ‘*’;char a[30];char a = “apple”;

Page 10: Variable declaration

< VARIABLE NAME >

arvin#030709buendia_arvin: ] supermansupermanarvin25buendia@arvin

arvin#030709buendia_arvin: ] supermansupermanarvin25buendia@arvin

Page 11: Variable declaration

< VARIABLE NAME >It must start with a letter or an underscore, with subsequent characters being letters, numbers, or the underscore

_arvinsuperman05buendiabuendia05%arvin*superman

_arvinsuperman05buendiabuendia05%arvin*superman

Page 12: Variable declaration

< VARIABLE NAME >A Turbo C Variable may consist of 63 characters, but only the first 32 are significant

do_you_know_that_this_is_one_long_variable_name_but_still_valid

do_you_know_that_this_is_one_long_variable_name_but_still_considered_as_invalid

tamahomemiyaka_mikaelarain_mikayla

tamahomemiyaka_mikaelarain_mikayla

Page 13: Variable declaration

< VARIABLE NAME >

A variable is case sensitive, that is, uppercase variables are treated differently 

Variable “SUM” is different from variable “sum”

Variable “NetPay” is different from variable “NETpay”

Variable “SUM” is different from variable “sum”

Variable “NetPay” is different from variable “NETpay”

Page 14: Variable declaration

< VARIABLE NAME >

A variable cannot be the same as a Turbo C keyword.

floatelwinmainpingdotaprintf

floatelwinmainpingdotaprintf

Page 15: Variable declaration

< VARIABLE NAME >

A variable cannot be the same as a Turbo C keyword.

floatelwinmainpingdotaprintf

floatelwinmainpingdotaprintf

Page 16: Variable declaration

< VARIABLE NAME >

Variable names must be unique and descriptive 

areasheverloucutesurnameproductchurva

areasheverloucutesurnameproductchurva

Page 17: Variable declaration

< DECLARING VARIABLES >

#include<stdio.h>main( ){int peso; printf(“Variable Value : %i”, peso);}

_Variable Value : _0_

00

00

Page 18: Variable declaration

< DECLARING VARIABLES >

#include<stdio.h>main( ){char let; printf(“Variable Value : %c”, let);}

_Variable Value : _ả _

ảảảả

Page 19: Variable declaration

< DECLARING VARIABLES >

#include<stdio.h>main( ){int x,y;printf(“Variable Values : %i %d”, x, y);}

_Variable Value : _0 _

00

VA

RIA

BL

E 1

VA

RIA

BL

E 1

VA

RIA

BL

E 2

VA

RIA

BL

E 2

00

00 00

0_

Page 20: Variable declaration

< DECLARING VARIABLES >

#include<stdio.h>main( ){float gross=5.84365;int age=3; printf(“Variable Values : %i %.3f”, age, gross);}

_Variable Value : _3 _

5.843655.84365

VA

RIA

BL

E 1

VA

RIA

BL

E 1

VA

RIA

BL

E 2

VA

RIA

BL

E 2

33 33 5.843655.84365

5.844_

Page 21: Variable declaration

< DECLARING VARIABLES >

#include<stdio.h>main( ){int a=5, b=6, c=7, para; para = a + b + c;printf(“PARAMETER : %i”, para);}

_PARAMETER _18_

55 66 77 00

55 66 771818

1818