Wednesday, September 2, 2015

Integer & Real/Float Conversion in C


Integer and float conversion

If you would like to develop an effective C program. Then you should understand/know about some rules for implicit conversion of integer and real/floating value in C language.

Important rules are defined below:-

1. When we would perform an arithmetic operation between an integer and an integer operation will always produce an integer result.

For ex. 1-    int + int = int;
          5 + 4 = 9;

2. When we would perform an arithmetic operation between a real and a real operation will always produce a real result.

    For ex. 2-    real + real = real;
              5.0 + 4.0 = 9.0;

3. When we would perform an operation between an integer and a real then this operation will always produce a real result. 

  For ex. 3-   int + real = real;
            5 + 4.0 = 9.0;

Process for example 3 - first integer will be promoted to a real constant/variable then this operation would be performed and result would be real.

RELATED TOPIC FROM C PROGRAMMING LANGUAGES :-

Tuesday, September 1, 2015

Instruction Type in C


In C programming language 3 types of instructions are available. These are as follows:-

1. Type declaration Instruction      
3. Control Instruction

1. Type Declaration Instruction:-


In C programming language every variable which is used in the program must be declared before its use in any further statements.
So, this instruction is used to declare the type of a variable being used in the program.

For ex.:- If we have to use "a" as a variable typed integer then we should declare it before using it as-
             int a;

Note-1 When we declare any variable at that time we are also eligible to initialize this variable.

For ex.  int i=5,j=7;
             float a=5.5;

Note-2 when we declare and initialize variables together the issue of ordering occurs.
Sometime order of declaration matters and sometime not.

For ex.   1) int i=10,j=25;                
   int j=25,i=10;
             here,order of variable declaration doesn't matter.
          2) float a=1.5,b=a+3.1;
              float b=a+3.1,a=1.5;