Unit 3 & 4 Input Output & Operators
Unit 3 & 4 Input Output & Operators
FUNCTION
Formatted I/O functions are used to take various inputs from the user and display
multiple outputs to the user. These types of I/O functions can help to display the output
to the user in different formats using the format specifiers.
These functions are called formatted I/O functions because we can use format specifiers
in these functions and hence, we can format these functions according to our needs.
printf() function
The printf() function is used for output. It prints the given statement to the console.
scanf() function
The scanf() function is used for input. It reads the input data from the console.
These functions are called unformatted I/O functions because we cannot use format
specifiers in these functions and hence, cannot format these functions according to our
needs.
getch()
getche()
getchar()
putchar()
gets()
puts()
putch()
Expression Statement in C
An expression statement consists of an expression followed by a semicolon. The
execution of such a statement causes the associated expression to be evaluated.
The symbol used to calculate the expression is called operator and except operator
everything is operand.
Example:
a = 6;
c = a + b;
++j;
C Operators
An operator is simply a symbol that is used to perform operations. There can be many
types of operations like arithmetic, logical, bitwise, etc.
Arithmetic Operator
Relational Operator
Logical Operators
Bitwise Operators
Assignment Operator
Ternary or Conditional Operators
Increment/Decrement Operator
Arithmetic Operators
An arithmetic operator performs mathematical operations such as addition, subtraction,
multiplication, division etc on numerical values (constants and variables).
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo Division
Relational Operators
A relational operator checks the relationship between two operands. If the relation is
true, it returns 1; if the relation is false, it returns value 0.
== Double equal to
!= Not equal to
Logical Operator
An expression containing logical operator returns either 0 or 1 depending upon whether
expression results true or false. Logical operators are commonly used in decision making
in C programming.
Bitwise Operators
Bitwise operators are used in C programming to perform bit-level operations.
Assignment Operator
An assignment operator is used for assigning a value to a variable. The most common
assignment operator is =.
=
+=
-=
*=
/=
%=
Conditional/Ternary Operator
The operators, which require three operands to act upon, are known as ternary
operators. It can be represented by “? :”. It is also known as conditional operator. The
operator improves the performance and reduces the line of code.
Syntax
Exmple
a<b ? a : b
Precedence of Operators in C
The precedence of operator species that which operator will be evaluated first and next.
The associativity specifies the operator direction to be evaluated; it may be left to right
or right to left.
int a=10+20*10;
The a variable will contain 210 because * (multiplicative operator) is evaluated before +
(additive operator).