C Instructions

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 10

C Instructions

C Instructions
Instruction: Combination of constants, variables and
keywords to form a meaningful & logical sentence.

There are basically four types of instructions in C


1. Type Declaration Instruction
2. Input/Output Instruction
3. Arithmetic Instruction
4. Control Instruction
Type Declaration Instruction
• To declare the type of variables used in a C program.
• Any variable used in the program must be declared
before using it in any statement.
• Type declaration statement is usually written at the
beginning of the C program

Ex: int bas;


float rs, gross_sal;
char name, code;
Type Input/Output Instruction
• To perform the function of supplying input data to a
program and obtaining the output results from it.

Ex: printf(“hello”);
printf(“%d”,a);
scanf(“%c”,ch);
Arithmetic Instruction
• To perform arithmetic operations between constants
and variables.
• Format of Instruction:

variable name = variable names & constants


connected with operators
(+,-,*,/)

Ex: delta = alpha * beta / gamma + 3.2 * 2 / 5


• Variables and constant together are called ‘operands’
Arithmetic Instruction…

Types of arithmetic instruction

1. Integer mode arithmetic statement – all operands are


either integer variables or integer constants.
2. Real mode arithmetic statement –all operands are
either real constants or real variables.
3. Mixed mode arithmetic –some of the operands are
integers and some of the operands are real.
Arithmetic Instruction…
execution of an arithmetic instruction
• z=x*y; x * y = z;
• Arithmetic operations can be performed on ints,
floats, and chars.
• No operator is assumed to be present. It must be
written explicitly.
a=c.d.(xy) usual arithmetic statement
b=c*d*(x*y) C statement
• There is no operator for performing exponentiation
operation.
a = 3 ** 2; b = 3 ^ 2;
Type Conversions
• Integer and Float Conversions
1. Integer = Integer (operator) integer
2. Real = Real (operator ) Real
3. Real = Integer (operator) Real
or
Real (operator) Integer

• Conversions in Assignments
Hierarchy of Operations
Priority Operators Description
1ST */% Multiplication, division,
Modular division
2nd +- Addition,
subtraction
3rd = Assignment

• Associativity
1. Z=a*b/c
2. Z=a*b+c/d
3. a=(b*(c*d+(e/f)))
Thank You

Questions
&
General Discussion

You might also like