tailieunhanh - Operators and Programming Constructs

Operators are used to compute results and compare the data values of a program. A program often involves decision-making and iterative tasks. To accomplish these tasks, programmers use various operators in the conditional and looping constructs. This chapter discusses the types of operators used in C# language. In addition, the conditional constructs and the looping constructs are also discussed. | Operators and Programming Constructs Operators are used to compute results and compare the data values of a program. A program often involves decision-making and iterative tasks. To accomplish these tasks programmers use various operators in the conditional and looping constructs. This chapter discusses the types of operators used in C language. In addition the conditional constructs and the looping constructs are also discussed. Chapter 3 Objectives In this chapter you will learn to fl Use various operators Arithmetic Arithmetic assignment Unary Comparison Logical fl Use conditional constructs fl Use looping constructs Using Operators Applications use operators to process the data entered by a user. Operators like and - are used to process variables and return a value. An operator is a set of one or more characters that is used for computations or comparisons. Operators can transform one or more data values called operands into a new data value. Consider the following expression X Y The preceding expression uses two operands and an operator to add the values stored in the variables. Operators in C can be classified as follows Arithmetic operators Arithmetic assignment operators Unary operators Comparison operators Logical operators Arithmetic Operators These operators are the symbols that are used to perform arithmetic operations on variables. The following table describes the commonly used arithmetic operators. Operator Description Example Used to add two numbers X Y Z If Y is equal to 20 and Z is equal to 2 X will have the value 22. - Used to subtract two numbers X Y-Z If Y is equal to 20 and Z is equal to 2 X will have the value 18. Used to multiply two numbers X Y Z If Y is equal to 20 and Z is equal to 2 X will have the value 40. NIIT Operators and Programming Constructs .