Sie sind auf Seite 1von 18

C- Language

Seer Akademi Pvt. Ltd., 2012

Seer Akademi Confidential

Data types
What is data type ?

A data type is which reserve (or) allocate memory for data.


Data type not only defines the type of value, it also define how much memory to be allocated for that value Integer: Signed integer: 2 bytes(-32768 to +32767) Un signed integer: 2 bytes (0 to 65535) Size modifiers: Alter the size of data type.

Seer Akademi Pvt. Ltd., 2012

Seer Akademi Confidential

1. Short. 2. Long.

Short int : rang 2 bytes.


Long int : 4 bytes. (-2,147,483,648 to 2,147,483,647) Unsigned long int: 4 bytes

Character : 1 byte Signed char: (-128 to 127) Unsigned char: (0 to 255) Seer Akademi Pvt. Ltd., 2012 Seer Akademi Confidential

Operators:
Binary operators

Unary operators
Ternary operators

Binary operators: Arithmetic operators Relational operators Logical operators Assignment operators Seer Akademi Pvt. Ltd., 2012 Seer Akademi Confidential

Arithmetic operators:

+, - , * , / , %.

(BODMAS)

Relational operators: >, <, >= ,=< , ==, !=.(returns either 0 r 1 )

Logical operators: &&, ||, !. ( evaluating more than one conditions )

Assignment operators: =, +=, -=, *=, /=, %=. (modify the value of variables) Unary operators: ++ operators. -- operators.

Seer Akademi Pvt. Ltd., 2012

Seer Akademi Confidential

Bitwise operators

++ operators: pre increment operator


post increment operator

Bitwise operators: &, |, ^(XOR), >>(R),<<(L). Ternary operators: Conditional operators: ?, : ,

Syntax: operand1 ? Operand2 : operand3; Seer Akademi Pvt. Ltd., 2012 Seer Akademi Confidential

IF Condition: Syntax: if(condition) { statements; } else { statements; } if(condition) { statements; } if(condition) statement; Seer Akademi Pvt. Ltd., 2012 Seer Akademi Confidential

LOOPS

While loop: syntax: while(expression) simple statement;

while(expression) { statements; statements; }

Seer Akademi Pvt. Ltd., 2012

Seer Akademi Confidential

Nested while:

Syntax:

while(exp) { while(exp) { statements; } }

Seer Akademi Pvt. Ltd., 2012

Seer Akademi Confidential

For loop :

For(exp1; exp2; exp3) Statement;

For(exp1; exp2; exp3) { Statement1; Statement2; Statement3; . . }


For(;exp2;exp3) { }

Seer Akademi Pvt. Ltd., 2012

Seer Akademi Confidential

For(exp1; ;exp3) { }

For(;;exp3) {
} For(; exp2;) { } For(; ;) { }

Seer Akademi Pvt. Ltd., 2012

Seer Akademi Confidential

For(exp1; exp2; exp3); ARRAYS What is an array ?

What is advantage?

Types : Single dimension array Multi dimension array Single dimension array:

Syntax: data type array _name [size];

Seer Akademi Pvt. Ltd., 2012

Seer Akademi Confidential

String :

Sting is collection of characters terminated with special character called null ( \0 ).

Syntax :

Char string_name [size]

Double dimensional array:

An array of single dimensional array is called. As double dimension array.


In double dimensional array data is organized logically dividing into rows and columns. Double dimensional array is a matrix.

Seer Akademi Pvt. Ltd., 2012

Seer Akademi Confidential

Syntax: data type array_name [row size][column size] Note : row size and column size must be constants but should not be variables.

SWITCH

Syntax:
Switch (exp) { Case constant-1 : statements : statements Case constant _n: statements : statements Seer Akademi Pvt. Ltd., 2012 Seer Akademi Confidential

Default: statements : statements } // end switch

Rules : Duplicate cases are not allowed. Expression must be of integer type. Default can be written any where in the switch. Case must be followed by a constant.

Seer Akademi Pvt. Ltd., 2012

Seer Akademi Confidential

POINTER
Pointer is a inherits the properties of the data type. A variable declared using pointer data type is called pointer Pointer variable holds an address of memory location. variable.

Syntax:

Data type *variable_name; Int *x; Float *y; Char *z; Double *d;

2 bytes

For any data type the size of pointer is 2 bytes, b/c it holding address not value.

Seer Akademi Pvt. Ltd., 2012

Seer Akademi Confidential

FUNCTIONS

A function is self contained block, containing set of instructions.

A function is a small program with in program.


A function is a reusable program. A function is a sub_routine. Advantages : Write once and use many times. It allows to avoid repetition of same instructions. It reduces the size of the program. Seer Akademi Pvt. Ltd., 2012 Seer Akademi Confidential

Function is divided into two parts: Function declaration (or) Function prototype. Function definition. Compiler recognize the function with prototype.

Function prototype:
Syntax: <return_type> function_name ([<parameter_type>]);

Function declaration:

Syntax:

function_name (parameters);

Function definition
Syntax: <return_type> function_name ([<parameter_type>])

Seer Akademi Pvt. Ltd., 2012

Seer Akademi Confidential

Das könnte Ihnen auch gefallen