COMPSCI 1101 ( SIR JAN) ( 2ND TERM)

studied byStudied by 32 People
5.0(2)
Get a hint
hint

5 types of Operators

1/91

Studying Progress

New cards
91
Still learning
0
Almost done
0
Mastered
0
91 Terms
New cards

5 types of Operators

• Assignment • Arithmetic • Relational • Logical • Special

New cards
New cards

is an syntactically correct combinations of operands and operators.

Expression

New cards
New cards

They both have a TYPE and VALUE

Operators and Expressions

New cards
New cards

Two basic types of arithmetic operators:

Unary and Binary

New cards
New cards

An operator that only requires one operand

Unary Operator

New cards
New cards

An operator that requires two operands

Binary Operator

New cards
New cards

There are only _____ arithmetic operator, and ______ arithmetic operators.

1 unary, 5 binary

New cards
New cards

Rules which determine precisely how expressions are evaluated

Rules of Precedence and Associativity

New cards
New cards

Terms which are always evaluated first

Expressions within the Parenthesis ( )

New cards
New cards

In ______ , all decimal portions of numbers are lost (or truncated).

Integer Arithmetic

New cards
New cards

Evaluates an arithmetic expression consisting of an operator and two integer operands.

Integer Arithmetic

New cards
New cards

Characterized by : variable = expression

Assignment Operator

New cards
New cards

Basic operator in C

Equal sign (=)

New cards
New cards

Can be used more than once in an expression

Assignment Operator

New cards
New cards

An assumption on which tests the validity or effect of something else

Condition

New cards
New cards

Are used to represent true or false because there is no actual boolean or logical data type in C

Integers

New cards
New cards

An expression that is either true (represented by 1) or false (represented by 0)

Condition

New cards
New cards

Are used to test specific conditions and requires the use of two operands

Relational Operator

New cards
New cards
Operators such as: != == < >

Relational Operator

New cards
New cards

Relational Operators == and != are often referred to as-

Equality Operators

New cards
New cards

Connects two or more relational expressions into one or reverse the logic of an expression.

Logical Operators

New cards
New cards

represents a non-zero value (can be negative or positive numbers, float, character, string)

True

New cards
New cards

represents a zero value (integer or float value)

False

New cards
New cards

symbol used as an increment operator to increment or add 1 to the operand value

Double Plus Symbol (++)

New cards
New cards

value is first incremented and then used inside the expression

Pre-Increment Operator

New cards
New cards

value is first used in an expression and then incremented

Post-Increment Operator

New cards
New cards

increment and decrement operators are considered as _____ since they require only one operand

Unary Operator

New cards
New cards

symbol used as an decrement operator to decrement or subtract 1 to the operand value

Double Minus Symbol (--)

New cards
New cards

value is first decremented and then used inside the expression

Pre-Decrement Operator

New cards
New cards

value if first used in an expression and then decremented

Post-Decrement Operator

New cards
New cards

operators used in special situations

Special Operator

New cards
New cards

5 types of special operator

Reference Operator Dereference Operator SizeOf Operator Ternary Operator Comma Operators

New cards
New cards

returns the address of the variable

Reference Operator

New cards
New cards

symbol used as a reference operator

&

New cards
New cards

returns the value of a variable pointed by the specified pointer

Dereference Operator

New cards
New cards

symbol used as a dereference operator

New cards
New cards

used to determine or compute the operand's size in bytes

SizeOf Operator

New cards
New cards

the size of int data type in the TurboC application, as it is a 16-bit-based application

2 bytes

New cards
New cards

the size of int data type in today's compilers (e.g., MinGW GCC Compiler)

4 bytes

New cards
New cards

size of char data type

1 byte

New cards
New cards

size of float data type

4 bytes

New cards
New cards

size of double data type

8 bytes

New cards
New cards

helps on creating a short way of writing conditional statements

Ternary Operator

New cards
New cards

syntax of ternary operator

condition ? S1 (True) : S2 (False)

New cards
New cards

comma can be used as a ____ or as a ____

Separator, Operator

New cards
New cards

has the least precedence of all C operators

Comma Operator

New cards
New cards

returns the rightmost value of an expression but first evaluate the rest of the expressions and discard their values

Comma Operator

New cards
New cards

way of converting one datatype to another

Type Conversion

New cards
New cards

automatically done by the compiler

Implicit Type Conversion

New cards
New cards

in the implicit type conversion, datatypes in the expression will be converted into the ________ datatype used within the expression

Largest

New cards
New cards

basic datatype upgrade sequence (least to greatest)

char -> int -> float -> double

New cards
New cards

specifies on which datatype to be converted

Explicit Type Conversion

New cards
New cards

explicit type conversion is also called as _______

Type Casting

New cards
New cards

There are three (3) basic classifications of statements in C, and actually, there are very few statements of each type.

PROGRAM STATEMENTS

New cards
New cards

(3) basic classifications of statements in C,

Primitives Decisions Loops

New cards
New cards

3 type of Primitive statements

Null Statement Simple Statement Compound Statement

New cards
New cards
  • is made up of a null expression followed by a semicolon.

  • a null expression is an empty expression

( ; )

Null Statement

New cards
New cards
  • Expression and function call statements expression; function_call();

Simple Statement

New cards
New cards
  • or also called as block is formed by placing more than one statement inside curly braces ({}). { statement; statement; }

Compound Statement

New cards
New cards

Conditional branches - make decision before branching: and its 2 type

Decision Statements

Single-decision branch Multi-decision branch

New cards
New cards

Single-decision branch - ____

  • if/else

New cards
New cards

Multi-decision branch

– switch/case

New cards
New cards

Decision statements are actually part of a larger category statements known as ??

branches

New cards
New cards

2 kinds of branch statements?

Conditional branches

Unconditional branches

New cards
New cards

involves making one or more decisions before branching, and are thus referred to as single-decision or multi-decision branches.

Conditional branches

New cards
New cards

direct branches which involve no decision. The goto statement is an example of an unconditional branch.

Unconditional branches

New cards
New cards

The___ statement is a conditional, single-decision branch.

if

New cards
New cards

The if statement has the general format of ?

if(expression) statement;

New cards
New cards

IF STATEMENTS may be a ____ statement or ___ statement.

simple compound

New cards
New cards

it allows you to check between multiple test expressions and execute different statements.

IF ELSE IF STATEMENTS

New cards
New cards

a conditional, multi-decision branch. The previous example of successive comparison of equality or value of the operand is so common in programming, a special construct exist in C to handle such comparison.

SWITCH-CASE STATEMENTS

New cards
New cards

____ is evaluated and its value is compared.

Expression

New cards
New cards

The expression and the constant compared against must be an _____ constants or expressions. They may NOT contain variables.

integer or character

New cards
New cards

The default case is optional, but if it exists there can be ____. It may occur anywhere in the list of case clauses but usually occur at the end

only one

New cards
New cards

One of the fundamental properties of a computer is its ability to repetitively execute a set of statements.

ITERATIVE STATEMENTS

New cards
New cards

These looping capabilities enable the programmer to develop concise programs containing repetitive processes that could otherwise require thousands of program statements to perform.

ITERATIVE STATEMENTS

New cards
New cards

C contains three looping constructs:

The while statement

The for statements

The do/while statements

New cards
New cards

The _____ statements may be described as test-before-execute. If the controlling condition results initially to a zero or false value, the body of the loop is never executed.

while and for

New cards
New cards

The ____statement on the other hand may be considered as execute-before-test. The body of the loop is always executed at least once.

do-while

New cards
New cards

The _____is used to execute a statement as long as a condition remains true.

with a syntax of

While (expression){ //statement }

while loop

New cards
New cards

The conditional expression, of course, may be a _____ or ____.

relational or arithmetic

New cards
New cards

_____ is usually used when the number of times the loop must be executed is not known in advance.

while loop

New cards
New cards

The ____ is generally used for counted loops.

for statement

New cards
New cards

The ______ will execute a statement and then evaluate a conditional expression.

do-while loop

New cards