Friday, September 20, 2013

C TOKEN , VARIABLES AND DATA TYPES

C TOKEN  , VARIABLES   AND   DATA  TYPES

C-TOKENS

Tokens are smallest individual units in C  program.

There are 6 types of tokens

Keyword

String

Identifier

Operator

Constant

Special symbol


KEYWORDS

They are reserved words used in  programming ,each keywords  has  a pre-defined meaning and that cannot be changed .

Example  int , char ,float  ,double  etc


STRINGS

The  array  of  character  are called  strings, A string  is  terminated with a null  character .

Example   "My course BCA "

Declaration of  strings
Char  s[5];
Strings are declared similar to arrays, the  difference is  string  of  char data  type.


IDENTIFIERS

Identifiers are  names  given to C entities  ,such as variables ,function,structures  etc.

Example
                                  Int   car;

      Here,  car is  a  identifier which is a variable of  type  integer  .

Rules for  identifers

1. Identifiers should  be composed  of  letters  ,digits  and  underscore.

2. The first letter of  identifier  should  be  either a letter or underscore.

3. There is  no rule  for  length  of   the  identifer.

OPERATOR

They  are  symbols which  operate on  value or variables.

Example :  '+'  operator  is  used for  addition.

Different operator  in  c

Arithmetic operator.

Increment and decrement operator.

Assignment operator.

Relational operator.

Conditional operator.

Bitwise operator.

Special character.

CONSTANTS

The constants refer to fixed values that the program may not alter during its execution. These fixed values are also called literals.

Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal. There are also enumeration constants as well.

The constants are treated just like regular variables except that their values cannot be modified after their definition.

Integer literals
An integer literal can be a decimal, octal, or hexadecimal constant. A prefix specifies the base or radix: 0x or 0X for hexadecimal, 0 for octal, and nothing for decimal.

214       /* Legal */
0xFeeL      /* Legal */
078         /* Illegal: 8 is not an octal digit */

Floating-point literals
A floating-point literal has an integer part, a decimal point, a fractional part, and an exponent part. You can represent floating point literals either in decimal form or exponential form.

3.14159       /* Legal */
314159E-5L    /* Legal */
510E          /* Illegal: incomplete exponent */

Character constants

Character literals are enclosed in single quotes, e.g., 'x' and can be stored in a simple variable of char type.

A character literal can be a plain character (e.g., 'y'), an escape sequence (e.g., '\t'), or a universal character (e.g., '\u02C0').

String literals
String literals or constants are enclosed in double quotes "". A string contains characters that are similar to character literals: plain characters, escape sequences, and universal characters.

You can break a long line into multiple lines using string literals and separating them using whitespaces.

Examples
"hello, dear"

Defining Constants
There are two simple ways in C to define constants:

Using #define preprocessor.

Using const keyword.

The #define Preprocessor
Following is the form to use #define preprocessor to define a constant:

#define identifier value

The const Keyword

You can use const prefix to declare constants with a specific type as follows:

const type variable = value;

Special  values

The special  values  used in c are ( ) " ; # % / { } [ ]


VARIABLES

Variables are memory location in computer memory to store data, to  indicate  the memory location ,each variable should  be

Given a unique name called identifier.

Variable  names  are just  symbolic  representation of  memory location.

Example :  car ,  Door_No etc.

Rules for writing variables are same as of  identifiers.

Declaration of  variables

Int num;

Here num is variable of  data type int , similarly you can use char , float double for  declaring different variables.

Initialization of variables

Num=10;

Assigning values to the variables is known as initialization.


DATA TYPES

In the C programming language, data types refer to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted.

The data types in C can be classified as follows:


1 Basic Types

They are arithmetic types and consists of the two types:
 (a) integer types and
(b) floating-point types.

2 Enumerated types

They are again arithmetic types and they are used to define variables that can only be assigned certain discrete integer values throughout the program.

3 The type void:
The type specifier void indicates that no value is available.

4 Derived types:
They include
(a) Pointer types,
(b) Array types,
 (c) Structure types,
 (d) Union types and
(e) Function types.




INTEGER  DATA TYPES


FLOATING DATA TYPE

No comments:

Post a Comment