Special Operators of C:
Program of Sizeof () Operator:
=> Shorthand Assignment Operators:
NOTE:
a += b;
printf("%d\n" , a);
Did you check the following?
That's All
- Comma Operator
- Size of()
- Address Operator
- Dereferencing Operator
- Dot Operator
- Arrow Operator
=> Sizeof () Operator:
- This Operator returns the size(i.e number of bytes) of operand.
- It should be written in lowercase Letter.
- The operand may be constant , a variable , or a data type.
- It is used for dynamic memory allocation.
- It is also used to determine the size of arrays and structures.
Syntax:
sizeof (operand); |
Example:
x = sizeof (int);
y = sizeof (sum);
Program of Sizeof () Operator:
Statement: This Program illustrates the use of sizeof () Operator:
{
int a;
float b;
char ch = 'c' ;
a = 2;
b = 10.0;
printf(" Size of a = %d\n" , sizeof (a) );
printf(" Size of b = %f\n" , sizeof (b) );
printf(" Size of ch = %c\n" , sizeof (ch) );
Output:
Size of a = 2
Size of b = 4
Size of ch = 1
=> Shorthand Assignment Operators:
- C provides a compact way of writing assignment Statements in an Expression.
- This is basically associated with all arithmetic Operators and bitwise Operators.
var | operator | = | exp | ; |
where
var => is a variable
operator => an airthmetic or bitwise operator
exp => is an Expression
NOTE:
- There is no space between the operator and the '=' sign in compact representation.
- Shorthand Assignment operators are easier to read , write and understand.
Program of Shorthand Assignment Operators:
{
int a , b , c;
a = 3;
b = 4;
c = 1;
a += b;
b -= a;
c *= x;
printf("%d\n" , a);
printf("%d\n" , b);
printf("%d\n" , c);
Output:
7
-1
5
Did you check the following?
That's All
0 Response to "Tutorial on Special Operators of C Language"
Post a Comment