C Tokens Identifiers Keywords Constants Operators Special symbols.

25
C Tokens • Identifiers • Keywords • Constants • Operators • Special symbols

Transcript of C Tokens Identifiers Keywords Constants Operators Special symbols.

Page 1: C Tokens Identifiers Keywords Constants Operators Special symbols.

C Tokens

• Identifiers• Keywords• Constants• Operators• Special symbols

Page 2: C Tokens Identifiers Keywords Constants Operators Special symbols.

Identifiers

• Identifiers are names given to various program elements such as variables, functions and arrays etc,.

• Eg: #define N 10#define a 15 Here N and a are user defined identifiers.

Page 3: C Tokens Identifiers Keywords Constants Operators Special symbols.

Rules for naming identifier• First character must be alphabetic or underscore.• Must consist only of alphabetic characters, digits, or

underscores.• Only the first 31 characters of an identifier are

significant and are recognized by the compiler.• Cannot use a keywords or reserved word (e.g. main,

include, printf & scanf etc.).• No space are allowed between the identifiers etc,.• C is case sensitive, e.g. My_name my_name.

Page 4: C Tokens Identifiers Keywords Constants Operators Special symbols.

Examples of Valid and Invalid Names

Valid Names Invalid Names

a a1 $sum /* $ is illegal */

student_name stdntNm 2names /* Starts with 2 */

_aSystemName _anthrSysNm stdnt Nmbr /* no spaces */

TRUE FALSE int /* reserved word */

Page 5: C Tokens Identifiers Keywords Constants Operators Special symbols.

Variables

• Variable is an identifier that is used to represent some specified type of information.

• Eg: x=3• Here x is variable.

Page 6: C Tokens Identifiers Keywords Constants Operators Special symbols.

Keywords

• It is a reserved words.• Cannot be used for anything else.• Examples:

– int– while– for etc,.

Page 7: C Tokens Identifiers Keywords Constants Operators Special symbols.

KeywordsAuto register ContinueDouble typedef ForInt Char signedStruct extern void Break return Default Else union GotoLong Const sizeof Switch Float doCase short IfEnum unsignedStatic While

Page 8: C Tokens Identifiers Keywords Constants Operators Special symbols.

Constants

• It is an entity whose value does not changes during the execution.

• Eg: x=3• Here 3 is a constant.

Page 9: C Tokens Identifiers Keywords Constants Operators Special symbols.

Types

• Numeric constants• Character constant

Page 10: C Tokens Identifiers Keywords Constants Operators Special symbols.

Constants

Constants

Character Constants Numeric Constants

RealConstant

IntegerConstant

String Constant

SingleCharacter Constant

Page 11: C Tokens Identifiers Keywords Constants Operators Special symbols.

Numeric constantsInteger constants• It is formed using a sequence of digits.

Decimal - 0 to 9 .Octal - 0 to 7.Hexa - 0 to 9 ,A to F

Eg: 10,75 etc.

Page 12: C Tokens Identifiers Keywords Constants Operators Special symbols.

Rules for defining Integer Constant

• It must have atleast one digit.• Decimal point are not allowed.• No blank space or commas are allowed.• It can be either positive or negative. Etc,.

Page 13: C Tokens Identifiers Keywords Constants Operators Special symbols.

Numeric constants

Real constants• It is formed using a sequence of digits but it

contain decimal point.• length, height, price distance measured in real

number Eg: 2.5, 5.11, etc.

Page 14: C Tokens Identifiers Keywords Constants Operators Special symbols.

Character constants

Single character constant– A character constant is a single character they also

represented with single digit or a single special symbol which is enclosed in single quotes.

– Eg: ‘a’, ‘8’,’_’etc.

Page 15: C Tokens Identifiers Keywords Constants Operators Special symbols.

Character constants

String constants• String constant are sequence of characters enclosed

with in double quote.• Eg: “Hello” ,”444”,”a” etc,.

Page 16: C Tokens Identifiers Keywords Constants Operators Special symbols.

Operators

• An operator is a symbol that specifies an operation to be performed on the operands.

• Eg: a + b+ is an operator.a,b are operands.

Page 17: C Tokens Identifiers Keywords Constants Operators Special symbols.

Data Types

· A Data type is the type of data that are going to access within the program.

Page 18: C Tokens Identifiers Keywords Constants Operators Special symbols.

Standard Data Types

These Standard type can be used to build more complex data types called Derived Types (e.g. pointers, array, union etc.).

Page 19: C Tokens Identifiers Keywords Constants Operators Special symbols.

Data typesData type Size(bytes) Range Format string

Char 1 -128 to 127 %c

int 2 -32,768 to 32,767 %d

Float 4 3.4 e-38 to 3.4 e+38 %f

Double 8 1.7 e-308 to 1.7 e+308 %lf

Page 20: C Tokens Identifiers Keywords Constants Operators Special symbols.

integer A number without a fraction part : integral

number. C supports three different sizes of the integer

data type :short intintlong int

Page 21: C Tokens Identifiers Keywords Constants Operators Special symbols.

Floating Point A floating-point type is a number with a

fractional part, e.g. 56.78 Floating point numbers are stored using 4 Byte. Types

Float Double long double

Page 22: C Tokens Identifiers Keywords Constants Operators Special symbols.

character

• Character are generally stored using 8 bits(1 Byte) of the internal storage.

Character ASCII code value

a 97(decimal) or 01100001(binary)

x 120(decimal) or 01111000(binary)

Page 23: C Tokens Identifiers Keywords Constants Operators Special symbols.

void The void type has no values and no operations. Both the set of values and the set of operations

are empty.

Page 24: C Tokens Identifiers Keywords Constants Operators Special symbols.

Variable’s Declaration

To create a variable, you must specify the type and then its identifier :

float price;int a,b;char code;

Page 25: C Tokens Identifiers Keywords Constants Operators Special symbols.

Entire Data types in c:Data type Size(bytes) Range Format string

Char 1 128 to 127 %c

Unsigned char 1 0 to 255 %c

Short or int 2 -32,768 to 32,767 %i or %d

Unsigned int 2 0 to 65535 %u

Long 4 -2147483648 to 2147483647 %ld

Unsigned long 4 0 to 4294967295 %lu

Float 4 3.4 e-38 to 3.4 e+38 %f or %g

Double 8 1.7 e-308 to 1.7 e+308 %lf

Long Double 10 3.4 e-4932 to 1.1 e+4932 %lf