C provides the facility of mixing different types of variable and constant in an expression.
Implicit Type Conversion:
Explicit Type Conversion:
Syntax: (Data type)expression
e.g z=float(x/y)
Platform to Think
C provides the facility of mixing different types of variable and constant in an expression.
Implicit Type Conversion:
Explicit Type Conversion:
Syntax: (Data type)expression
e.g z=float(x/y)
An operator specifies an operation to be performed that yields a value.
1.Arithmetic operators
2. Assignment operators .
3. Increment and Decrement operators
4. Relational operators.
5. Logical operators
6. Conditional operator
7. Comma operator
8. Sizeof operator
9. Bitwise operators
10. Other operators
1. Arithmetic operators: It is used for numeric calculations.
They are of two types:
1. Unary Arithmetic Operators
2. Binary Arithmetic Operators
Unary Arithmetic Operators: Unary operators require only one operand. For e.g +x -y
Binary Arithmetic Operators: Binary operators require two operands. There are five binary arithmetic operators.
Integer Arithmetic: In which both operands are integer
Floating-Point Arithmetic: In which both operands are integer type.
2. Assignment Operator : A value can be stored in a variable with the use of assignment operator.
The operator ‘=’ is used in assignment operator & statement.
3. Increment/ Decrement Operators: These are the unary operators because they operate on a single operand. Increment(++) and decrement(--) used to increase and decrease the value by 1.
2. Postfix Increment/ Decrement:
4. Relational Operators:
It is used to compare values of two expressions depending on their relationship.
Let us take two variables a=9 and b=5 . Evaluate the value.
5. Logical Operators: An expression that combines two or more expressions in terms of logical expression. The operator returns 0 for false and 1 for true.
1.AND(&&) Operator: This gives true if both conditions are true, otherwise the result is false.
2. OR(||) Operators: This operator gives results false , if both conditions are false, otherwise the result is true.
3. Not(!) Operator: This is a unary operator and it negates the value of the condition . If the value of the condition is false then it gives the value true.
6. Conditional Operator: Conditional operator is a ternary (? And :) which requires three expressions as operands.
Syntax: TestExpression ? Expression1: Expression2
e.g. a > b ? a : b
Suppose a=5 and b=8 then,
Max=a > b ? a : b
Sizeof Operator: It is a unary operator . This operator gives the size of its operand in terms of bytes . The operand can be variable, constant or any data types( int, float, char etc)
Algorithm: an algorithm is a procedure or formula for solving a problem. The word and derived from the name of the mathematician. An algorithm is a step-wise procedure written in a simple language. If equation solution of any problem that written in human language is called as algorithm.
Algorithm is a first step of the solution process, after the
analysis of the problem, program for write the algorithm of that problem.
Write an algorithm to find a number is even or odd.
Step 1: Start
Step 2: Input a number
Step 3: rem= number mod 2
Step 4: if rem= 0 then
print “even number”
else
print
“odd number”
end if
Step 5: Stop
Flowchart: chat is a means of visually presenting the flow of the data through an information processing system, the operations performed within the system and the sequence in which they are performed. in this lesson, we shall concern yourself with a program flowchart, which describe what operations and in what sequence are required to solve a given problem. The program flowchart that can be likened to the blueprint of a building. As we know a designer draws a blueprint before starting construction on a building. Similarly a program word brief was to draw a flowchart prior to writing a computer program. As in the case of the growing of a blueprint, the flowchart is drawn according to define rule and using standard for chat symbol prescribed by the ANSI.
Meaning of flowchart: a flowchart is a diagrammatic representation that illustrates the sequence of operation to be performed to get a better solution of problem. who chart are generally draw in the early stages of formulating Computer Solutions. Flowchart facilitates communication between the program office and business people. These four charges play a vital role in programming of the problem and are quite helpful in understanding the logic of the complicated and then the problem. Once the flowchart is drawn in become easy to write the program in any high level language. Often we see how the Charter helpful in explaining the program to others. is it is correct to say that flow chart is a must for better documentation of complex program.
Symbols used in flowchart:
Guidelines of flowchart drawing:
Enumeration: An enumeration type is a user defined data type, which can take values only from a user defined list or named integer constants called enumerators.
Syntax:
enum tag
{
member1;
member2;
…………;
………...
} ;
Here enum is a keyboard, tag is an identifier that specifies the
name of the new enumeration type of being defined, member1, member2 are identifiers
which represent integer constant are
called enumerator constant or enumerator. The list of these enumerators is
called as enumerator list.
After the definition, we can declare variable of these new data type as -
enum tag var1, var2, var3;
Here var1, var2, var3 are variables of type enum tag. This variable can take value from the enumerator list.
The variable can also be declared with the definition as-
enum tag
{
member1;
member2;
…………;
………...
} var1, var2, var3;
Example:
enum month {Jan, Feb, Mar, Apr, May, Jun};
Here a new data type month is define and the enumerator list
contains six enumerators. internally the compiler treat the numerator as
integer constant. these are automatically assign integer values beginning
from 0,1,2..
Jan 0
Feb 1
Mar 2
Apr 3
.
Desired for values assigned to enumerator. it is also possible to explicitly assign any value to enumerator.
enum month {Jan, Feb=4, Mar, Apr, May=11, Jun};
Jan 0
Feb 4
Mar 5
Apr 6
May 11
Jun 12
We can assign any signed integer value to the enumerator.
enum boolean{true, false};
enum switch{off, on};
enum subject{Phy, Chem, Math, Cs, Ele}
Format Specifiers:
Reading Input Data: Input data can be entered into the memory from a standard input device (keyboard). C provides the scanf( ) library function for entering input data. This function can take all types of values (numeric, character, string) as input.
The
scanf( ) function can be written as
scanf("control string" , address1, address2, ....);
This function should have at least two parameters. First parameter is a control string, which contains conversion specification characters. It should be within double quotes.
The address of a variable is found by preceding the variable name by an ampersand (&) sign. This sign is called the address operator and it gives the starting address of the variable name in memory
Writing Output Data: Output data can be written from computer memory to the standard output device (monitor) usIng printf() library function. With this function all type of values (numeric, character or string) can be written as output.
The printf( ) function can be written as
printf("control
string", variable 1, variable 2, );
In this function the control string contains conversion specification characters and text. It should be enclosed within'double quotes. The name of variables snould not be preceded by an ampersand(&) sign.
Some example of printf( ) function are as-