Presentation is loading. Please wait.

Presentation is loading. Please wait.

At the end of the module the students should be able to:  Familiarize themselves with the different uses of constants, operators, and expressions in.

Similar presentations


Presentation on theme: "At the end of the module the students should be able to:  Familiarize themselves with the different uses of constants, operators, and expressions in."— Presentation transcript:

1

2 At the end of the module the students should be able to:  Familiarize themselves with the different uses of constants, operators, and expressions in Turbo C programming.  Apply the different functions of constants, operators, and expressions in building C programs.

3  Constants in C refer to fixed values that may not be altered by the program. They can be of any data type.  C supports one other type of constant in addition to those of the predefined data types. This is a string. All string constants are enclosed between double quotes, such as “this is a test”. You must not confuse strings with characters. A single character constant is enclosed by single quotes, such as ‘a’. Strings are simply arrays of characters.

4 Data TypeConstant Examples char‘a’ ‘\n’ ‘9’ “d” int 1 123 21000 -234 long int10 -12 90 float23.23 4.3e-3

5  Enclosing all character constants in single quotes works for most printing characters, but a few, such as the carriage return, are impossible to enter from the keyboard. For this reason, C uses the special backslash character constants, shown in the table below.

6  You use a backslash code exactly the same way you would any other character. For example, ch = ‘\t’; printf(“this is a test\n”); cout<<“this is a test\n”;

7 CodeMeaning  \Backspace  \fForm feed  \nNewline  \r Carriage return  \tHorizontal tab

8  \”Double quote  \’Single quote character  \0Null  \\Backslash  \vVertical tab  \aAlert  \oOctal constant  \xHexadecimal constant

9  ARITHMETIC  LOGICAL  RELATIONAL

10 Operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. There are three classes of operators in C: arithmetic, logical and relational, and bitwise.

11 OperatorAction  + Addition  -Subtraction  *Multiplication  /Division  %Modulus Divisor  --Decrement a value  ++Increment a value

12 Increment and Decrement  C++ allows two very useful operators not generally found in other computer languages. These are the increment and decrement operators, ++ and --. The operation ++ adds 1 to its operand, and -- subtracts 1.

13 The following are equivalent operations: x = x+1; is the same as ++x;  Also, x = x-1; is the same as --x;

14 Relational and Logical Operators “In the term relational operator, the word relational refers to the relationship values can have with one another. In the term logical operator, the word logical refers to the ways these relationships can be connected together using the rules of formal logic. The key to the concept or relational and logical operators is the idea of true or false.”

15 Relational Operators OperatorFunction  >Greater than  >= Greater than or equal to  <Less than  <=Less than or equal to  ==Equal  !=Not equal

16 LOGICAL OPERATORS OPERATORACTION &&AND ||OR !NOT

17 Truth Table true && true = true true && false = false false && true = false false && false = false true ║ true = true true ║ false = true false ║ true = true false ║ false = false ! true = false ! false = true


Download ppt "At the end of the module the students should be able to:  Familiarize themselves with the different uses of constants, operators, and expressions in."

Similar presentations


Ads by Google