80 likes | 232 Views
Data Type and Variable. 2012/10/08 NCTU CS. Outline. Data Type Variable Arithmetic Practice Time. Data Type (1/2). Boolean( bool ) true as 1, false as 0 Character( char ) Character, i.e. ‘A ’ Integer( short , int , long ) Integer values, i.e. 4,-10,0
E N D
Data Type and Variable 2012/10/08 NCTU CS
Outline • Data Type • Variable • Arithmetic • Practice Time
Data Type (1/2) • Boolean(bool) • true as 1, false as 0 • Character(char) • Character, i.e. ‘A’ • Integer(short , int , long) • Integer values, i.e. 4,-10,0 • Floating point(float , double , long double) • Real numbers, i.e. 0.000001
Data Type (2/2) • Size • The actual size varies by implementation. • In Visual studio 2010 e.g. printf("%d\n", sizeof(float));
Variable int myStudentID = 1234567 ; Value Data type Variable name
Arithmetic(1/2) firstInt • Reads 123 from standard input stream. Stores 123 to firstInt
Practice Time • Write a program to calculate s = [(x+y) * f] – 5 You need to use prompt e.g. p.s. Don’t forget #include <stdio.h>