Professional Documents
Culture Documents
R. C. Patel Polytechnic, Shirpur: First Year Diploma in Computer Engineering
R. C. Patel Polytechnic, Shirpur: First Year Diploma in Computer Engineering
Programming In C
Data Types
Basic Derived User-defined
• Character (char) • Arrays • Structure (struct)
• Integer (int) • Functions • Union (union)
• Float (float) • Pointers • Enumeration (enum)
• Double • Type Definition
(double) (typedef)
• Void (void)
! 33 * 42 < 60 ^ 94
“ 34 + 43 = 61 _ 95
# 35 , 44 > 62 ‘ 96
$ 36 - 45 ? 63 a-z 97-122
% 37 . 46 @ 64 { 123
Classification of Operators
Based on No. of Based on Role of
Operands Operators
• Unary • Arithmetic
• Binary • Logical
• Ternary • Relational
• Bitwise
• Assignment
•
1. Arithmetic Operators
+ : Addition * : Multiplication ++ : Increment (pre & post)
- : Subtraction / : Division -- : Decrement (pre & post)
% : Modulus
✯ For example: Consider three variables declared as, int a=9, b=3, result;
Operation Operator Syntax Comment Result
Multiply * a*b result = a * b 18
Divide / a/b result = a / b 3
Addition + a+b result = a + b 12
Subtraction - a–b result = a – b 6
Modulus % a%b result = a % b 0
✯ While performing modulo division, the sign of the result is always the sign of the
first operand (the dividend). Therefore,
16 % 3 = 1 -16 % 3 = -1
16 % -3 = 1 -16 % -3 = -1
16 % 3.0 16.5% 4 compiler error
Introduction to C VC-ICP (Vocational Course on Introduction to C Programming
Increment & Decrement Operators
✯ ++ and -- are unary operators which perform increment & decrement operation.
✯ The increment operator (++) is used to add 1 to its operand and the
decrement operator (--) is used to subtract 1 from its operand.
✯ In other words, a = a + 1 is the same as ++a or a++ and
a = a – 1 is the same as --a or a--.
✯ These operators can be applied only to variables by using either the prefix form
(i.e. pre-increment/decrement) or postfix form (post-increment /decrement).
✯ Writing 2++, 2--, --2 or ++2 will cause error. It cannot modify a constant, a
variable is required.
✯ When a prefix form (++x or --x) is used, the value of the variable is either
incremented or decremented first and then assigned. However, in the postfix
form, the value is used and after the assignment operator has performed the
operation, the value is incremented or decremented.
Introduction to C VC-ICP (Vocational Course on Introduction to C Programming
Increment & Decrement Operators