1 Introduction to Scientific and Engineering Computation (BIL 110E) Lecture 3 Data Types and Keywords & Handling Standard (Input/Output) 1 C Keywords Keyword Description auto Storage class specifier / modifier const extern register static volatile Keyword Description default Label sizeof Operator The C language reserves certain words ( C keywords ) that have special meanings to the language. You should not use the C keywords as an identifiers such as variable, constant, or function names. 2
2 C Keywords Keyword Description char Type specifier double float register int long short signed struct union unsigned void Keyword Description break Statement case continue do else for goto if return switch typedef while All C keywords are written in lowercase letters. int is considered as a C keyword , but INT is not. Because C is a case sensitive language 3 Data Types: char An object of the char data type represents a single character of the character set used by your computer. Decimal Hex Binary Value Explanation 4
3 Data Types: char Decimal Hex Binary Value Explanation 5 Data Types: char A computer can only store numeric code ( binary code ). Therefore, characters such as A, a, B, b, and so on all have a unique numeric code. Usually, a character takes 8 bits ( 1 byte ) to store its numeric code. 8 bits 1 byte 0,1 0,1 0,1 0,1 0,1 0,1 0,1 0,1 Different characters can be represented by 1 byte. 8 2 2 5 6 There are two possiblities ( 0 and 1 ) for each bit area. 6
4 Data Types: Character Variables A variable that can represent different characters is called a character variable char variable_name; C syntax char variable_name1; char variable_name2; char variable_name3; C syntax char variable_name1, variable_name2, variable_name3; C syntax For instance: char MyCharacter = ‘A’; This statement declares MyCharacter and sets it to ‘A’. char x, y, z; x = ‘A’; y = ‘;’; z = ‘7’; This statements declare x , y, and z as character variables and then assign values to them. x 65 y 59 z 55 7 Data Types: Character Constants A character enclosed in single quotes (‘) is called a character constant . For instance: x = ‘A’; x = 65 ; y = ‘a’ ; y = 97 ; Two assignment statements are equivalent for each declaration couple. y = a ; This statement assigns value contained in variable a into variable y. Character constants are always surrounded by single quote characters (‘) while a string of more than one character uses the double quote ( “) 8
5 Data Types: The Escape Character ( \ ) The backslash ( \ ) is called the escape character in the ASCII character set .
You've reached the end of your free preview.
Want to read all 17 pages?
- Fall '19
- ASCII, Unicode