Variable Declaration
Usually Variables are declared before use either at the start of a block of code after the opening { and before any other statements or outside a function.
--------------------------
int a,b; /* global variables */
main()
{
float a; /* local variables */
}
--------------------------
Local variables can only accessed within that function only whereas Global variables can access in whole program.
3.1.2 Variable Types
There are many 'built-in' data types in C.
short int -128 to 127 (1 byte)
unsigned short int 0 to 255 (1 byte)
char 0 to 255 or -128 to +127 (1 byte)
unsigned char 0 to 255 (1 byte)
signed char -128 to 127 (1 byte)
int -32,768 to +32,767 (2 bytes)
unsigned int 0 to +65,535 (2 bytes)
long int -2,147,483,648 to +2,147,483,647 (4 bytes)
unsigned long int 0 to 4,294,967,295 (4 bytes)
float single precision floating point (4 bytes)
double double precision floating point (8 bytes)
long double extended precision floating point (10 bytes)
3.1.3 Variable Names
we can use any combination of letters and numbers for Variable and function names but it must start with a letter.
We can use Underscore (_) as a letter in variable name and can begin with an underscore But Identifiers beginning with an underscore are reserved, And identifiers beginning with an underscore followed by a lower case letter are reserved for file scope identifiers Therefore using underscore as starting letter is not desirable.
Akki and akki are different identifiers because upper and lower case letters are treated as different identifiers
Operators
An operator is a symbol. Compiler identifies Operator and performs specific mathematical or logical operation. C provides following operators :
# Arithmetic Operators
# Increment and Decrement Operators
# Relational Operators
# Logical Operators
# Cast Operators
# Bitwise Operators
# Assignment Operators
3.2.1 Arithmetic Operators
* multiplication
/ division
% remainder after division (modulo arithmetic)
+ addition
- subtraction and unary minus
3.2.2 Increment and Decrement Operators
Increment and decrement operators are used to add or subtract 1 from the current value of oprand.
++ increment
-- decrement
Increment and Decrement operators can be prefix or postfix. In the prefix style the value of oprand is changed before the result of expression and in the postfix style the variable is modified after result.
For eg.
a = 9;
b = a++ + 5; /* a=10 b=14 */
a = 3;
b = ++a + 6; /* a=10 b=15 */
3.2.3 Relational Operators
== equal.
!= Not equal.
> < Greater than/less than
>= greater than or equal to
<= less than or equal to
3.2.4 Logical Operators
&& Called Logical AND operator. If both the operands are non-zero, then condition becomes true.
|| Called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true.
! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true, then Logical NOT operator will make false.
3.2.5 Cast Operators
Cast operators are used to convert a value from one to another type.
(float) sum; converts type to float
(int) fred; converts type to int
3.2.6 Bitwise Operators
Bitwise operators performs operation on actual bits present in each byte of a variable. Each byte contain 8 bits, each bit can store the value 0 or 1
~ one's complement
& bitwise AND
^ bitwise XOR
| bitwise OR
<< left shift (binary multiply by 2)
>> right shift (binary divide by 2)
3.2.7 Assignment Operators
= assign
+= assign with add
-= assign with subtract
*= assign with multiply
/= assign with divide
%= assign with remainder
>>= assign with right shift
<<= assign with left shift
&= assign with bitwise AND
^= assign with bitwise XOR
|= assign with bitwise OR
For example,
a = a + 64; is same as
a += 64;



0 Comments