The document discusses operators and expressions in C#. It covers various categories of operators like arithmetic, logical, comparison, assignment, and other operators. It provides examples of using different operators and discusses operator precedence. It also covers implicit and explicit type conversions in C# expressions.
The document discusses operators in C# for performing calculations. It covers arithmetic, logical, comparison, assignment, and other operators. It explains operator precedence and describes implicit and explicit type conversions. Expressions are defined as sequences of operators and operands that are evaluated to a single value. Examples are provided to demonstrate the use of various operators and expressions to perform calculations in C#.
The document discusses operators and expressions in C#. It describes different categories of operators like arithmetic, logical, comparison, assignment, and other operators. It explains operator precedence and associativity. It also covers implicit and explicit type conversions. Expressions are defined as sequences of operators and operands that are evaluated to a single value. Examples are provided to demonstrate the use of various operators and expressions.
The document discusses various operators in C# including arithmetic, logical, bitwise, comparison, and assignment operators. It provides examples of using each operator type and discusses operator precedence. Key points covered include the different categories of operators in C#, how they work, precedence rules, and examples of using each type of operator to perform calculations and comparisons in C# code.
The document discusses the different types of operators in C++, including unary, binary, ternary, arithmetic, logical, comparison, assignment, bitwise, and special operators like scope resolution (::), endl, and setw. It provides examples of how each operator is used, such as increment/decrement for unary, addition/subtraction for binary, conditional operator ?: for ternary, and manipulating bits with bitwise operators. The document also explains how scope resolution allows accessing global variables from inner blocks and how endl and setw are used for formatting output displays.
Increment and Decrement operators in C++Neeru Mittal
The document discusses C++ increment and decrement operators. It explains that these unary operators work only on integers, and can be used in both prefix (++a) and postfix (a++) forms. In prefix form, the increment/decrement occurs before the expression is evaluated. In postfix form, it occurs after. The key difference is that prefix returns the new value, while postfix returns the original value. Several examples are provided to illustrate this behavior. Finally, some practice questions are included to help test understanding of these fundamental operators.
This document discusses operators and expressions in C++. It begins by defining operators as symbols that represent operations and operands as the objects involved in those operations. It then covers various types of operators in C++ like arithmetic, relational, logical, and conditional operators. It provides examples of using each operator and notes order of precedence. The document also discusses expressions, noting they are combinations of operators, constants, and variables. It provides examples of integer, real, relational, and logical expressions. Finally, it discusses mathematical functions available in the C++ standard library header file math.h that can be used in arithmetic expressions.
Operators in C and C++ Programming Language:
Operators are the symbols which tells the language compiler to perform a specific mathematical or logical function. C and C++ programming is very rich in Operators. C and C++ Language Provides the following type of Operator:-
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operators
6. Misc Operators
You will Study all these operators with these Slides. Hope you will find it helpful. If you find it helpful then please Let others know by Like and Sharing. If you don't like so please let us know. So that i can make it more better.
If you have to ask anything about any operator then you can ask in comments.
Thankyou for visit
Sahyog Vishwakarma
The document discusses operators in C# for performing calculations. It covers arithmetic, logical, comparison, assignment, and other operators. It explains operator precedence and describes implicit and explicit type conversions. Expressions are defined as sequences of operators and operands that are evaluated to a single value. Examples are provided to demonstrate the use of various operators and expressions to perform calculations in C#.
The document discusses operators and expressions in C#. It describes different categories of operators like arithmetic, logical, comparison, assignment, and other operators. It explains operator precedence and associativity. It also covers implicit and explicit type conversions. Expressions are defined as sequences of operators and operands that are evaluated to a single value. Examples are provided to demonstrate the use of various operators and expressions.
The document discusses various operators in C# including arithmetic, logical, bitwise, comparison, and assignment operators. It provides examples of using each operator type and discusses operator precedence. Key points covered include the different categories of operators in C#, how they work, precedence rules, and examples of using each type of operator to perform calculations and comparisons in C# code.
The document discusses the different types of operators in C++, including unary, binary, ternary, arithmetic, logical, comparison, assignment, bitwise, and special operators like scope resolution (::), endl, and setw. It provides examples of how each operator is used, such as increment/decrement for unary, addition/subtraction for binary, conditional operator ?: for ternary, and manipulating bits with bitwise operators. The document also explains how scope resolution allows accessing global variables from inner blocks and how endl and setw are used for formatting output displays.
Increment and Decrement operators in C++Neeru Mittal
The document discusses C++ increment and decrement operators. It explains that these unary operators work only on integers, and can be used in both prefix (++a) and postfix (a++) forms. In prefix form, the increment/decrement occurs before the expression is evaluated. In postfix form, it occurs after. The key difference is that prefix returns the new value, while postfix returns the original value. Several examples are provided to illustrate this behavior. Finally, some practice questions are included to help test understanding of these fundamental operators.
This document discusses operators and expressions in C++. It begins by defining operators as symbols that represent operations and operands as the objects involved in those operations. It then covers various types of operators in C++ like arithmetic, relational, logical, and conditional operators. It provides examples of using each operator and notes order of precedence. The document also discusses expressions, noting they are combinations of operators, constants, and variables. It provides examples of integer, real, relational, and logical expressions. Finally, it discusses mathematical functions available in the C++ standard library header file math.h that can be used in arithmetic expressions.
Operators in C and C++ Programming Language:
Operators are the symbols which tells the language compiler to perform a specific mathematical or logical function. C and C++ programming is very rich in Operators. C and C++ Language Provides the following type of Operator:-
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operators
6. Misc Operators
You will Study all these operators with these Slides. Hope you will find it helpful. If you find it helpful then please Let others know by Like and Sharing. If you don't like so please let us know. So that i can make it more better.
If you have to ask anything about any operator then you can ask in comments.
Thankyou for visit
Sahyog Vishwakarma
This chapter discusses different operators in C including arithmetic, assignment, equality/relational, logical, and conditional operators. It explains unary and binary arithmetic operators, the difference between pre- and post-increment operators, and precedence rules for evaluating expressions with multiple operators. Logical operators allow testing of multiple conditions and the conditional operator provides a simplified if/else statement syntax.
Lecture 2 C++ | Variable Scope, Operators in c++Himanshu Kaushik
The document discusses variable scope and operators in C++. It explains that variables can have local, global, or formal parameter scope depending on where they are declared. Local variables are only accessible within the block they are declared in, while global variables can be accessed anywhere. It then provides examples of various arithmetic, relational, logical, and bitwise operators in C++ and shows how to use assignment operators.
Operators are symbols that perform specific tasks like mathematical or logical operations on operands or values. There are several types of operators in C/C++ including arithmetic, relational, logical, bitwise, assignment, conditional, and special operators. Arithmetic operators perform math operations like addition, subtraction, multiplication, and division. Relational operators check relationships between operands like equality, greater than, less than. Logical operators perform logical AND, OR, and NOT operations.
The document discusses various elements of programming in C++ including literals, variables, types, expressions, statements, control flow constructs, functions, and libraries. It then focuses on different types of operators in C++ like arithmetic, relational, logical, and bitwise operators. It explains operator precedence and associativity rules for evaluating expressions. Special assignment operators, increment/decrement operators, and their differences are also covered.
Operators in C++ represent specific tasks or operations that are applied to operands. There are several types of operators including arithmetic, relational, logical, increment/decrement, and conditional operators. Arithmetic operators perform basic math operations like addition, subtraction, multiplication, and division on operands. Relational operators compare operands and return true or false based on the comparison. Logical operators combine relational expressions and include logical AND, logical OR, and logical NOT. The increment/decrement operators increment or decrement operands by 1. The conditional operator returns one of two results based on a condition. Precedence rules determine the order in which operations are performed.
Operators in Python include arithmetic, relational, logical, bitwise and assignment operators. Arithmetic operators perform mathematical operations like addition and multiplication. Relational operators compare values and return True or False. Logical operators combine conditional statements. Bitwise operators work on operands as binary digits and assignment operators assign values to variables. Special operators like identity and membership are also used. Operator precedence defines the order calculations are performed.
The document discusses various C# operators including unary operators, binary operators, and ternary operators. It provides examples and explanations of increment/decrement, bitwise, logical, comparison, and assignment operators. It also covers operator precedence and uses the Math class for common mathematical functions.
This document discusses arithmetic, logical, and relational operations and expressions in C++. It covers basic arithmetic operations like addition, subtraction, multiplication, and division. It also discusses arithmetic expressions, precedence rules, assignment statements, initializing variables, relational operations, logical operations, unary operators, and good programming style practices like indenting, comments, and using constants.
Mesics lecture 4 c operators and experssionseShikshak
Operators in C allow operations to be performed on operands. Common operators include arithmetic, relational, logical, and bitwise operators. Operators have precedence and associativity that determine the order of operations. The conditional operator (?:) evaluates a condition and returns one of two expressions. Operators are used to perform calculations, comparisons, assignments, and logical tests in C programs.
This document discusses various operators in C++ programming including arithmetic, relational, logical, and bitwise operators. It provides examples of using each operator and explains their functionality such as performing calculations, comparisons, and bit manipulations. It also outlines four tasks for a C++ lab, including programs to calculate the cube of a number, display a character, demonstrate increment/decrement and relational operators, and calculate the sum and average of floating point numbers.
This document provides an introduction to C++ programming. It discusses key differences between C and C++, shows simple C++ examples, and covers important C++ concepts like input/output streams, header files, inline functions, references, and reference parameters. The document is intended to teach basic C++ syntax and features to someone new to the language.
This document discusses different types of operators in Python programming. It defines operators as symbols that represent operations that can be performed on operands or values. The main types of operators covered are: arithmetic operators for mathematical operations, relational operators for comparisons, logical operators for Boolean logic, assignment operators for assigning values, and special operators like identity and membership. Examples are provided to demonstrate the usage of each operator type.
The document discusses various operators in C programming language. It classifies operators into arithmetic, relational, logical, bitwise, assignment and special operators. It provides examples of using different operators and explains their precedence rules and associativity.
The document discusses various operators in Python including arithmetic, comparison, bitwise, logical, and membership operators. It provides examples of using each operator and explains their functionality. The key types of operators covered are arithmetic (e.g. +, -, *, /), comparison (e.g. ==, !=, >, <), bitwise (e.g. &, |, ^), logical (e.g. and, or, not), and membership (e.g. in, not in) operators. It also discusses operator precedence and provides examples of expressions using different operators.
The aim of this list of programming languages is to include all notable programming languages in existence, both those in current use and ... Note: This page does not list esoteric programming languages. .... Computer programming portal ...
03. Operators Expressions and statementsIntro C# Book
In this chapter we will get acquainted with the operators in C# and the actions they can perform on the different data types. We will explain the priorities of the operators and we will analyze the different types of operators, according to the count of the arguments they can take and the actions they can perform. In the second part we will examine the conversion of data types. We will explain when and why it is needed to be done and how to work with different data types. At the end of the chapter we will pay special attention to the expressions and how we should work with them.
This document discusses operators, loops, and formatted input/output functions in C. It covers various categories of operators, how they work, and precedence rules. Loops like for, while and do-while are explained along with break and continue. Formatted I/O functions printf() and scanf() are described, including their syntax and use of format specifiers for input and output of different data types.
The document discusses the basics of C++ programming including:
- Source code is written in a high-level language and saved with file extensions like .cpp.
- The compiler converts source code into machine-readable object code. It checks for syntax errors and translates the program.
- The linker combines object code with library files to create an executable file with a .exe extension that can be run by the operating system.
This document provides an overview of basic C# programming concepts. It covers topics such as program structure, data types, variables, operators, decision making statements, loops, classes and methods. Specifically, it discusses if/else statements, switch cases, ternary operators, for, while and do-while loops. It also provides examples of basic C# programs and explanations of concepts like classes, methods, constructors and namespaces.
This chapter discusses different operators in C including arithmetic, assignment, equality/relational, logical, and conditional operators. It explains unary and binary arithmetic operators, the difference between pre- and post-increment operators, and precedence rules for evaluating expressions with multiple operators. Logical operators allow testing of multiple conditions and the conditional operator provides a simplified if/else statement syntax.
Lecture 2 C++ | Variable Scope, Operators in c++Himanshu Kaushik
The document discusses variable scope and operators in C++. It explains that variables can have local, global, or formal parameter scope depending on where they are declared. Local variables are only accessible within the block they are declared in, while global variables can be accessed anywhere. It then provides examples of various arithmetic, relational, logical, and bitwise operators in C++ and shows how to use assignment operators.
Operators are symbols that perform specific tasks like mathematical or logical operations on operands or values. There are several types of operators in C/C++ including arithmetic, relational, logical, bitwise, assignment, conditional, and special operators. Arithmetic operators perform math operations like addition, subtraction, multiplication, and division. Relational operators check relationships between operands like equality, greater than, less than. Logical operators perform logical AND, OR, and NOT operations.
The document discusses various elements of programming in C++ including literals, variables, types, expressions, statements, control flow constructs, functions, and libraries. It then focuses on different types of operators in C++ like arithmetic, relational, logical, and bitwise operators. It explains operator precedence and associativity rules for evaluating expressions. Special assignment operators, increment/decrement operators, and their differences are also covered.
Operators in C++ represent specific tasks or operations that are applied to operands. There are several types of operators including arithmetic, relational, logical, increment/decrement, and conditional operators. Arithmetic operators perform basic math operations like addition, subtraction, multiplication, and division on operands. Relational operators compare operands and return true or false based on the comparison. Logical operators combine relational expressions and include logical AND, logical OR, and logical NOT. The increment/decrement operators increment or decrement operands by 1. The conditional operator returns one of two results based on a condition. Precedence rules determine the order in which operations are performed.
Operators in Python include arithmetic, relational, logical, bitwise and assignment operators. Arithmetic operators perform mathematical operations like addition and multiplication. Relational operators compare values and return True or False. Logical operators combine conditional statements. Bitwise operators work on operands as binary digits and assignment operators assign values to variables. Special operators like identity and membership are also used. Operator precedence defines the order calculations are performed.
The document discusses various C# operators including unary operators, binary operators, and ternary operators. It provides examples and explanations of increment/decrement, bitwise, logical, comparison, and assignment operators. It also covers operator precedence and uses the Math class for common mathematical functions.
This document discusses arithmetic, logical, and relational operations and expressions in C++. It covers basic arithmetic operations like addition, subtraction, multiplication, and division. It also discusses arithmetic expressions, precedence rules, assignment statements, initializing variables, relational operations, logical operations, unary operators, and good programming style practices like indenting, comments, and using constants.
Mesics lecture 4 c operators and experssionseShikshak
Operators in C allow operations to be performed on operands. Common operators include arithmetic, relational, logical, and bitwise operators. Operators have precedence and associativity that determine the order of operations. The conditional operator (?:) evaluates a condition and returns one of two expressions. Operators are used to perform calculations, comparisons, assignments, and logical tests in C programs.
This document discusses various operators in C++ programming including arithmetic, relational, logical, and bitwise operators. It provides examples of using each operator and explains their functionality such as performing calculations, comparisons, and bit manipulations. It also outlines four tasks for a C++ lab, including programs to calculate the cube of a number, display a character, demonstrate increment/decrement and relational operators, and calculate the sum and average of floating point numbers.
This document provides an introduction to C++ programming. It discusses key differences between C and C++, shows simple C++ examples, and covers important C++ concepts like input/output streams, header files, inline functions, references, and reference parameters. The document is intended to teach basic C++ syntax and features to someone new to the language.
This document discusses different types of operators in Python programming. It defines operators as symbols that represent operations that can be performed on operands or values. The main types of operators covered are: arithmetic operators for mathematical operations, relational operators for comparisons, logical operators for Boolean logic, assignment operators for assigning values, and special operators like identity and membership. Examples are provided to demonstrate the usage of each operator type.
The document discusses various operators in C programming language. It classifies operators into arithmetic, relational, logical, bitwise, assignment and special operators. It provides examples of using different operators and explains their precedence rules and associativity.
The document discusses various operators in Python including arithmetic, comparison, bitwise, logical, and membership operators. It provides examples of using each operator and explains their functionality. The key types of operators covered are arithmetic (e.g. +, -, *, /), comparison (e.g. ==, !=, >, <), bitwise (e.g. &, |, ^), logical (e.g. and, or, not), and membership (e.g. in, not in) operators. It also discusses operator precedence and provides examples of expressions using different operators.
The aim of this list of programming languages is to include all notable programming languages in existence, both those in current use and ... Note: This page does not list esoteric programming languages. .... Computer programming portal ...
03. Operators Expressions and statementsIntro C# Book
In this chapter we will get acquainted with the operators in C# and the actions they can perform on the different data types. We will explain the priorities of the operators and we will analyze the different types of operators, according to the count of the arguments they can take and the actions they can perform. In the second part we will examine the conversion of data types. We will explain when and why it is needed to be done and how to work with different data types. At the end of the chapter we will pay special attention to the expressions and how we should work with them.
This document discusses operators, loops, and formatted input/output functions in C. It covers various categories of operators, how they work, and precedence rules. Loops like for, while and do-while are explained along with break and continue. Formatted I/O functions printf() and scanf() are described, including their syntax and use of format specifiers for input and output of different data types.
The document discusses the basics of C++ programming including:
- Source code is written in a high-level language and saved with file extensions like .cpp.
- The compiler converts source code into machine-readable object code. It checks for syntax errors and translates the program.
- The linker combines object code with library files to create an executable file with a .exe extension that can be run by the operating system.
This document provides an overview of basic C# programming concepts. It covers topics such as program structure, data types, variables, operators, decision making statements, loops, classes and methods. Specifically, it discusses if/else statements, switch cases, ternary operators, for, while and do-while loops. It also provides examples of basic C# programs and explanations of concepts like classes, methods, constructors and namespaces.
The document discusses various types of operators in C programming language. It describes arithmetic, conditional, bitwise, relational and logical operators. For arithmetic operators, it explains integer, real and mixed-mode arithmetic. For bitwise operators, it provides details about logical operators like AND, OR and XOR as well as shift operators. It also discusses one's complement operation. The document serves as a report submitted to provide information about different categories of operators supported in C language.
The document discusses various operators in C++, including unary, arithmetic, shift, relational, and bitwise operators. It provides examples of how each operator is used, what it does, and sample code demonstrating its usage. The key operators covered are unary operators like - and !, arithmetic operators like + and -, shift operators like << and >>, and relational operators like ==, !=, >, <, >=, and <=.
Operators in Python are special symbols or keywords that are used to perform operations on variables and values. Python supports various types of operators, each designed for specific purposes.
This document discusses various types of operators in C programming. It describes arithmetic, relational, logical, assignment, increment/decrement, conditional, bitwise, and special operators. Examples are provided for each type of operator to demonstrate their usage. The key types of operators covered are arithmetic (e.g. +, -, *, /), relational (e.g. <, >, ==), logical (e.g. &&, ||), assignment (=), increment/decrement (++, --), and conditional/ternary (?:) operators. Special operators like sizeof and comma operators are also briefly explained.
C operators allow building expressions and performing operations in C programs. The main types of operators in C are arithmetic, assignment, logical/relational, bitwise, and others like sizeof. Arithmetic operators perform math operations like addition and subtraction. Assignment operators assign values. Logical operators allow conditional logic. Relational operators compare values. Bitwise operators work at the bit level. Precedence rules determine the order calculations are performed. Operators are used with operands and follow consistent rules in C.
C operators allow building expressions and making decisions in code. The document discusses several categories of operators in C including arithmetic, assignment, relational, logical, bitwise, and others. It provides examples of using each type of operator and explains precedence rules and associativity. Key points covered include: how each operator works; common uses like conditional checks, assignments, and bit manipulation; and important considerations like order of operations and integer division behavior.
The document discusses various operators in C# programming including unary, binary, and ternary operators. It explains operators such as increment, decrement, bitwise inversion, logical, assignment, comparison, arithmetic, and more. Examples are provided to demonstrate how each operator works. The document also covers operator precedence and escape sequences.
The document discusses various operators in C# programming including unary, binary, and ternary operators. It explains operators such as increment, comparison, bitwise, logical, assignment, and escape sequence operators. It also covers Math class methods for common mathematical operations.
The document discusses various types of operators in Java including arithmetic, unary, assignment, relational, logical, ternary, bitwise, and shift operators. It provides examples to demonstrate the usage of each type of operator and the output. Key operator types covered are arithmetic (+, -, *, /, %), unary (++, --, !), assignment (=, +=, -=, etc.), relational (==, !=, <, >, etc.), logical (&&, ||) and examples are given for each.
The document discusses operators in the C programming language. It defines different types of operators such as arithmetic, relational, logical, and assignment operators. It provides examples of using various operators like addition, subtraction, multiplication, division, modulus, increment, decrement, relational, and logical operators. It also covers operator precedence and associativity rules for evaluating expressions containing multiple operators.
This document discusses data types in C# programming. It covers increment and decrement operators, assignment operators, basic data types like integers, floats and booleans. It also discusses constants, conditional logical operators like AND, OR and NOT. Examples are provided to demonstrate how to use these operators and data types in C# code. The objectives are to learn about these fundamental programming concepts in C#.
The document discusses various types of operators in the C programming language. It describes operators as symbols that are used to perform logical and mathematical operations on variables and constants to form expressions. The main types of operators covered are arithmetic, assignment, relational, logical, bitwise, conditional/ternary, and increment/decrement operators. Examples are provided to demonstrate the use of each operator type.
Similar to 3 operators-expressions-and-statements-120712073351-phpapp01 (20)
The document discusses operators and expressions in C#. It covers various categories of operators like arithmetic, logical, comparison, assignment, and other operators. It provides examples of using different operators and discusses operator precedence. It also covers implicit and explicit type conversions in C# expressions.
Part 3-functions1-120315220356-phpapp01Abdul Samee
The document provides information about functions in C++. It defines what a function is, how functions are called and defined. It discusses function parameters, return types, and function prototypes. It covers local and global variables, call by value vs call by reference, and recursion. It also discusses function overloading, where multiple functions can have the same name but different parameters.
The document discusses various input and output devices used in computer systems. It describes common input devices like the keyboard, mouse, trackball, joystick, dataglove, digitizer, image scanners, lightpen, barcode reader, optical mark reader, and voice systems. It also explains popular output display devices such as monitors with CRT and flat panel displays, as well as printers including dot matrix, laser, and inkjet printers. Lastly, it briefly mentions plotters and their uses.
Strings are immutable sequences of characters represented by the System.String class in .NET. The document discusses various methods for manipulating strings such as comparing, concatenating, searching, extracting substrings, splitting, replacing, deleting, changing case, and trimming. It recommends using a StringBuilder for efficient modification and building of strings. Formatting strings can be done using the ToString() and String.Format() methods along with formatting placeholders. Parsing numbers and dates from strings is culture-sensitive.
Recursion is a technique where a method calls itself directly or indirectly. It is useful for solving problems that involve repeating patterns or combinatorial algorithms. The document provides examples of calculating factorials, generating all binary vectors, and finding all paths in a labyrinth recursively. It discusses how to avoid harmful recursion that uses excessive memory and discusses when recursion is preferable to iteration, such as for problems that require exploring multiple continuations at each step. Exercises are provided to help practice implementing various recursive algorithms.
This document discusses arrays in C#, including declaring and creating arrays, accessing array elements, input and output of arrays, iterating over arrays using for and foreach loops, dynamic arrays using List<T>, and copying arrays. It provides examples of declaring, initializing, accessing, reversing, and printing arrays. It also covers reading arrays from console input, checking for symmetry, and processing arrays using for and foreach loops. Lists are introduced as a resizable alternative to arrays. The document concludes with exercises for practicing various array techniques.
4. What is an Operator?
Operator is an operation performed over data
at runtime
Takes one or more arguments (operands)
Produces a new value
Operators have precedence
Precedence defines which will be evaluated first
Expressions are sequences of operators and
operands that are evaluated to a single value
4
5. Operators in C#
Operators in C# :
Unary – take one operand
Binary – take two operands
Ternary (?:) – takes three operands
Except for the assignment operators, all
binary operators are left-associative
The assignment operators and the
conditional operator (?:) are right-associative
5
6. Categories of Operators in C#
Category Operators
Arithmetic + - * / % ++ --
Logical && || ^ !
Binary & | ^ ~ << >>
Comparison == != < > <= >=
Assignment
= += -= *= /= %= &= |=
^= <<= >>=
String concatenation +
Type conversion is as typeof
Other . [] () ?: new
6
11. Arithmetic Operators
Arithmetic operators +, -, * are the same as in
math
Division operator / if used on integers returns
integer (without rounding) or exception
Division operator / if used on real numbers
returns real number or Infinity or NaN
Remainder operator % returns the remainder
from division of integers
The special addition operator ++ increments a
variable 11
12. Arithmetic Operators – Example
12
int squarePerimeter = 17;
double squareSide = squarePerimeter / 4.0;
double squareArea = squareSide * squareSide;
Console.WriteLine(squareSide); // 4.25
Console.WriteLine(squareArea); // 18.0625
int a = 5;
int b = 4;
Console.WriteLine( a + b ); // 9
Console.WriteLine( a + b++ ); // 9
Console.WriteLine( a + b ); // 10
Console.WriteLine( a + (++b) ); // 11
Console.WriteLine( a + b ); // 11
Console.WriteLine(12 / 3); // 4
Console.WriteLine(11 / 3); // 3
21. Bitwise Operators
Bitwise operator ~ turns all 0 to 1 and all 1 to 0
Like ! for boolean expressions but bit by bit
The operators |, & and ^ behave like ||, && and ^
for boolean expressions but bit by bit
The << and >> move the bits (left or right)
Behavior of the operators|, & and ^:
21
Operation | | | | & & & & ^ ^ ^ ^
Operand1 0 0 1 1 0 0 1 1 0 0 1 1
Operand2 0 1 0 1 0 1 0 1 0 1 0 1
Result 0 1 1 1 0 0 0 1 0 1 1 0
22. Bitwise Operators (2)
Bitwise operators are used on integer numbers
(byte, sbyte, int, uint, long, ulong)
Bitwise operators are applied bit by bit
Examples:
22
ushort a = 3; // 00000000 00000011
ushort b = 5; // 00000000 00000101
Console.WriteLine( a | b); // 00000000 00000111
Console.WriteLine( a & b); // 00000000 00000001
Console.WriteLine( a ^ b); // 00000000 00000110
Console.WriteLine(~a & b); // 00000000 00000100
Console.WriteLine( a << 1); // 00000000 00000110
Console.WriteLine( a >> 1); // 00000000 00000001
23. Bitwise Operators –Tips &Tricks
How to get the bit at position p in a number n?
How to set the bit at position p to 0?
23
int p = 5;
int n = 35; // 00000000 00100011
int mask = 1 << p; // 00000000 00100000
int nAndMask = n & mask; // 00000000 00100000
int bit = nAndMask >> p; // 00000000 00000001
Console.WriteLine(bit); // 1
int p = 5;
int n = 35; // 00000000 00100011
int mask = ~(1 << p); // 11111111 11011111
int result = n & mask; // 00000000 00000011
Console.WriteLine(result); // 3
24. Bitwise Operators –
Tips &Tricks (2)
How to set the bit at position p to 1?
How to print a binary number to the console?
24
int p = 4;
int n = 35; // 00000000 00100011
int mask = 1 << p; // 00000000 00010000
int result = n | mask; // 00000000 00110011
Console.WriteLine(result); // 3
Console.WriteLine(
Convert.ToString(result, 2).PadLeft(32, '0'));
// 00000000000000000000000000110011
27. Comparison Operators
Comparison operators are used to compare
variables
==, <, >, >=, <=, !=
Comparison operators example:
27
int a = 5;
int b = 4;
Console.WriteLine(a >= b); // True
Console.WriteLine(a != b); // True
Console.WriteLine(a == b); // False
Console.WriteLine(a == a); // True
Console.WriteLine(a != ++b); // False
Console.WriteLine(a > b); // False
28. Assignment Operators
Assignment operators are used to assign a
value to a variable ,
=, +=, -=, |=, ...
Assignment operators example:
28
int x = 6;
int y = 4;
Console.WriteLine(y *= 2); // 8
int z = y = 3; // y=3 and z=3
Console.WriteLine(z); // 3
Console.WriteLine(x |= 1); // 7
Console.WriteLine(x += 3); // 10
Console.WriteLine(x /= 2); // 5
31. Other Operators
String concatenation operator + is used to
concatenate strings
If the second operand is not a string, it is
converted to string automatically
31
string first = "First";
string second = "Second";
Console.WriteLine(first + second);
// FirstSecond
string output = "The number is : ";
int number = 5;
Console.WriteLine(output + number);
// The number is : 5
32. Other Operators (2)
Member access operator . is used to access
object members
Square brackets [] are used with arrays
indexers and attributes
Parentheses ( ) are used to override the
default operator precedence
Class cast operator (type) is used to cast one
compatible type to another
32
33. Other Operators (3)
Conditional operator ?: has the form
(if b is true then the result is x else the result is y)
The new operator is used to create new objects
The typeof operator returns System.Type
object (the reflection of a type)
The is operator checks if an object is
compatible with given type
33
b ? x : y
34. Other Operators
Null-coalescing operator ?? is used to define a
default value for both nullable value types and
reference types
It returns the left-hand operand if it is not null
Otherwise it returns the right operand
34
int? x = null;
int y = x ?? -1;
int? x = 1;
int y = x ?? -1;
Here the value of y is -1
Here the value of y is 1
35. Other Operators – Example
Using some other operators:
35
int a = 6;
int b = 4;
Console.WriteLine(a > b ? "a>b" : "b>=a"); // a>b
Console.WriteLine((long) a); // 6
int c = b = 3; // b=3; followed by c=3;
Console.WriteLine(c); // 3
Console.WriteLine(a is int); // True
Console.WriteLine((a+b)/2); // 4
Console.WriteLine(typeof(int)); // System.Int32
int d = new int();
Console.WriteLine(d); // 0
38. ImplicitType Conversion
Implicit type conversion
Automatic conversion of value of one data type
to value of another data type
Allowed when no loss of data is possible
"Larger" types can implicitly take values of
smaller "types"
Example:
38
int i = 5;
long l = i;
39. ExplicitType Conversion
Explicit type conversion
Manual conversion of a value of one data type
to a value of another data type
Allowed only explicitly by (type) operator
Required when there is a possibility of loss of
data or precision
Example:
39
long l = 5;
int i = (int) l;
40. Type Conversions – Example
Example of implicit and explicit conversions:
Note: Explicit conversion may be used even if
not required by the compiler
40
float heightInMeters = 1.74f; // Explicit conversion
double maxHeight = heightInMeters; // Implicit
double minHeight = (double) heightInMeters; // Explicit
float actualHeight = (float) maxHeight; // Explicit
float maxHeightFloat = maxHeight; // Compilation error!
43. Expressions
Expressions are sequences of operators,
literals and variables that are evaluated to
some value
Examples:
43
int r = (150-20) / 2 + 5; // r=70
// Expression for calculation of circle area
double surface = Math.PI * r * r;
// Expression for calculation of circle perimeter
double perimeter = 2 * Math.PI * r;
44. Expressions (2)
Expressions has:
Type (integer, real, boolean, ...)
Value
Examples:
44
int a = 2 + 3; // a = 5
int b = (a+3) * (a-4) + (2*a + 7) / 4; // b = 12
bool greater = (a > b) || ((a == 0) && (b == 0));
Expression of type
int. Calculated at
compile time.
Expression
of type int.
Calculated
at runtime.
Expression of type bool.
Calculated at runtime.
46. Summary
We discussed the operators in C#:
Arithmetic, logical, bitwise, comparison,
assignment and others
Bitwise calculations
Operator precedence
We learned when to use implicit and explicit
type conversions
We learned how to use expressions
46
48. форум програмиране,форум уеб дизайн
курсове и уроци по програмиране,уеб дизайн – безплатно
програмиранеза деца – безплатни курсове и уроци
безплатен SEO курс -оптимизация за търсачки
уроци по уеб дизайн, HTML,CSS, JavaScript,Photoshop
уроци по програмиранеи уеб дизайн за ученици
ASP.NET MVCкурс – HTML,SQL,C#,.NET,ASP.NETMVC
безплатен курс"Разработка на софтуер в cloud среда"
BG Coder -онлайн състезателна система -online judge
курсове и уроци по програмиране,книги – безплатно отНаков
безплатен курс"Качествен програменкод"
алго академия – състезателно програмиране,състезания
ASP.NET курс -уеб програмиране,бази данни, C#,.NET,ASP.NET
курсове и уроци по програмиране– Телерик академия
курсмобилни приложения с iPhone, Android,WP7,PhoneGap
freeC#book, безплатна книга C#,книга Java,книга C#
Дончо Минков -сайт за програмиране
Николай Костов -блог за програмиране
C#курс,програмиране,безплатно
Operators and Expressions
http://academy.telerik.com
49. Exercises
1. Write an expression that checks if given integer is
odd or even.
2. Write a boolean expression that checks for given
integer if it can be divided (without remainder) by 7
and 5 in the same time.
3. Write an expression that calculates rectangle’s area
by given width and height.
4. Write an expression that checks for given integer if
its third digit (right-to-left) is 7. E. g. 1732 true.
5. Write a boolean expression for finding if the bit 3
(counting from 0) of a given integer is 1 or 0.
6. Write an expression that checks if given point (x, y)
is within a circle K(O, 5). 49
50. Exercises (2)
7. Write an expression that checks if given positive
integer number n (n ≤ 100) is prime. E.g. 37 is prime.
8. Write an expression that calculates trapezoid's area
by given sides a and b and height h.
9. Write an expression that checks for given point (x, y)
if it is within the circle K( (1,1), 3) and out of the
rectangle R(top=1, left=-1, width=6, height=2).
10. Write a boolean expression that returns if the bit at
position p (counting from 0) in a given integer
number v has value of 1. Example: v=5; p=1 false.
50
51. Exercises (3)
11. Write an expression that extracts from a given
integer i the value of a given bit number b.
Example: i=5; b=2 value=1.
12. We are given integer number n, value v (v=0 or 1)
and a position p.Write a sequence of operators that
modifies n to hold the value v at the position p from
the binary representation of n.
Example: n = 5 (00000101), p=3, v=1 13 (00001101)
n = 5 (00000101), p=2, v=0 1 (00000001)
51
52. Exercises (4)
13. Write a program that exchanges bits 3, 4 and 5 with
bits 24, 25 and 26 of given 32-bit unsigned integer.
14. *Write a program that exchanges bits {p, p+1, …,
p+k-1) with bits {q, q+1, …, q+k-1} of given 32-bit
unsigned integer.
52
53. FreeTrainings @Telerik Academy
Fundamentals of C# Programming
Course
csharpfundamentals.telerik.com
Telerik Software Academy
academy.telerik.com
Telerik Academy @ Facebook
facebook.com/TelerikAcademy
Telerik Software Academy Forums
forums.academy.telerik.com