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 versionsPrefixPostfixDifference b/w prefix and postfixPrefixPostfix 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 operatorsExample-1: int a = 3, b = 4,c; c = ++a * ++b; printf("%d %d %d",a,b,c); //4 5 20 Example-2: int a = 3,b = 4, c; c = a++ * b++; printf("%d %d %d",a,b,c);…

Operators in C Language | Part-3

Relational OperatorRelational operators are used to perform a logical test or create a condition. List of the logical operator is as given below...Relational opertorMeaning>Greater Than<Less Than>=Greater Than or Equal to<=Less Than or Equal to==Equal to!=Not euqalEvery 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), || (or) are used to combine two or more conditions.Each condition can be true or false, so what will be the output of the combination made by logical…

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 AssignmentEquivalent Expressiona += 5a = a + 5a -= 5a = a - 5a *= 5a = a * 5a /= 5a = a / 5a %= 5a = a % 5PreviousBack to C Programming indexNext

Operators in C Language

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 operatorAccording 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 operatorUnary operatorAssignment operatorRelational operatorLogical operatorBitwise operatorConditional operator(ternary operator)Comma operatorArithmetic operator+,-,*,/,%(mod) are called the arithmetic operator.The +,-,* are same as you learn in mathematical Arithmetic.To more understand take an example.5 + 3 * 4In 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 evaluated, then divide,after that Multiply,addition and …

Popular posts from this blog

Overview of Go lang

Arrays in C Language

Data Types in Go language

Creating your first html page

Say Hello world in Go lang

Arrays in Go lang

Installing go lang

String in golang

Decision Making in Go lang

Decision Making Statements