C Program Instructions

Tuesday, October 21, 2008 | | 0 comments »

The previous post of the resource deals with C Program compilation and execution and it will be helpful to understand this topic.

The purpose of instructions is

  1. Type declaration instruction : To declare the type of variables used in a C program.
  2. Arithmetic instruction : To perform arithmetic operations between constants and variables.
  3. Control instruction : To control the sequence of execution of various statements in a C program.
Type Declaration Instruction is used to declare the type of variables being used in the program. Any variable used in the program must be declared before using it in any statement. The type declaration statement is written at the beginning of main( ) function.

Ex.:

int bas ;
float rs, grosssal ;
char name, code ;

There are several subtle variations of the type declaration instruction.

1 . While declaring the type of variable we can also initialize it as shown below.

int i = 10, j = 25 ;
float a = 1.5, b = 1.99 + 2.4 * 1.44 ;

2 . The order in which we define the variables is sometimes important sometimes not.

For example,
int i = 10, j = 25 ;
is same as
int j = 25, j = 10 ;

However,
float a = 1.5, b = a + 3.1 ; is alright,
but float b = a + 3.1, a = 1.5 ; is not. This is because here we are trying to use a even before defining it.

3 . The following statements would work .
int a, b, c, d ; a = b = c = 10 ;
However, the following statement would not work
int a = b = c = d = 10 ; Once again we are trying to use b (to assign to a) before defining it.

Arithmetic Instruction

A arithmetic instruction consists of a variable name on the left hand side of = and variable names & constants on the right hand side of =. The variables and constants appearing on the right hand side of = are connected by arithmetic operators like +, -, *, and /.

Ex :

int ad ;
float kot, deta, alpha, beta, gamma ;
ad = 3200 ; kot = 0.0056 ;
deta = alpha * beta / gamma + 3.2 * 2 / 5 ;

Here, *, /, -, + are the arithmetic operators. = is the assignment operator. 2, 5 and 3200 are integer constants. 3.2 and 0.0056 are real constants. ad is an integer variable. kot, deta, alpha, beta, gamma are real variables.

The variables and constants together are called ‘operands’ that are operated upon by the ‘arithmetic operators’ and the result is assigned, using the assignment operator, to the variable on left-hand side.
42
You can go through the complete c programming course here.

To Do Next: Thank you for visiting PROGRAMMING BLOG. If you liked the post, please subscribe to my blog via email or RSS FEED.You can contact me here for any specific feed back .
Bookmark and Share
AddThis Feed Button

0 comments

Post a Comment