Posts

Showing posts with the label operators in C

Operators in C Language| Part-4

Unary operators Unary operator are those which only require one operand(argument) to operate. + , - , ++, --, typecast and sizeof are some unary operators in C programming. +5, -5 are the example of +,- unary operators. which represents +ve and -ve values. Unary operators have high priority than binary operators, so unary operators are always evalutes first. Increment / Decrement operator ++, -- are called increment and decrement operators. Increment and decrement operators are available in two versions Prefix Postfix Difference b/w prefix and postfix Prefix Postfix int a = 5; ++a; printf("%d",a); // 6 int a = 5; a++; printf("%d",a); // 6 int a = 5,b; b = ++a; printf("%d %d",a,b);// 6 6 int a = 5,b; b = a++; printf("%d %d",a,b);//6 5 Example of increment and decrement operators Example-1: int a = 3, b = 4,c; c = ++a * ++b; printf("%d %d %d",a,b,c); /

Operators in C Language | Part-3

Relational Operator Relational operators are used to perform a logical test or create a condition. List of the logical operator is as given below... Relational opertor Meaning > Greater Than < Less Than >= Greater Than or Equal to <= Less Than or Equal to == Equal to != Not euqal Every relational operator returns true or false. In C any non-zero is treated as true and zero is treated as false. In C if any expression evaluated true then system returns 1 otherwise return 0. Relational operator are evaluated from left to right. Example-1 printf("%d",5>2); //print 1 Example-2 printf("%d",5>2>1); //print 0 //first 5>2 evaluated true and returns 1 and then result of this expression is compared with next 1, that is evaluated false. Logical Operator &&(And) ||(Or) !(not) are the 3 logical operators. &&(and),

Operators in C Language | Part-2

Assignment operator = operator is called assignment operator. It is used to move the value or expression result in a variable. Assignment operator are evaluated from right to left order. Example of assignment: a = b = 5 , In this example the 5 is assignment in b then b's value is moved to a. a = b + 5 , Assignment operator have the lowest precedence so all other operator are evaluated first and then result is moved to the variable. 5 = a , This is an error, because in this example we are trying to move the value of variable into constant and constant can't be changed.The same error will be prompted if you are try the expression 6 + b = a . Compound assignment +=, -=, *=, /=, %= are called compound assignment operator. It combine the Arithmetic as well as assignment simultaneously. Compound Assignment Equivalent Expression a += 5 a = a + 5 a -= 5 a = a - 5 a *= 5 a = a * 5 a /= 5 a = a / 5 a %= 5 a = a

Operators in C Language

Image
Observe the given expression y = x + 5. In the above given expression +, = are the operators and x, y, 5 are called operands / argument. Types of operator According to the required argument the operator can be classified into 3 categories: unary operator: require only one argument. example(-5) binary operator: require two argument. example(5+8) ternary operator: require 3 argument. example(?:) According to the purpose operator are again classified into 8 types: Arithmetic operator Unary operator Assignment operator Relational operator Logical operator Bitwise operator Conditional operator(ternary operator) Comma operator Arithmetic operator +,-,*,/,%(mod) are called the arithmetic operator. The +,-,* are same as you learn in mathematical Arithmetic. To more understand take an example. 5 + 3 * 4 In the above given expression, which operator should be evaluates first? As in mathematics you learn the rule of BODMAS,which tells first brackets should be ev

Popular posts from this blog

String in golang

Inline V/S Block Level Element

Arrays in C Language

Data Types in Go language

Printing in C programming

Variable Naming & Scope of Variable

Escape Sequence | Formatted Printing | Interview Questions

Floating point Data types in Go lang

Overview of Go lang

Literals in Java