Constants and Operators Flashcards
refer to fixed values that the program may not alter during its
execution
Constants
fixed values
Literals
Constants may belong to
any of the data type
basic data types
integer constant
floating-point constant
character constant or a string literal
enumeration constant (enum)
Two data types that must have at least one digit
Integer and Floating Point Constants
A data type that must not have a decimal point
Integer Constants
Two data types that can either be positive or negative
Integer and Floating Point Constants
No commas or blanks are allowed within __
Integer Constant and Real Constant
If no sign precedes an integer constant, then
it is assumed to be positive.
An integer constant is assumed to be positive if
no sign precedes an integer constant
The allowable range for integer constants is
-32768 to 32767
A data type that must have a decimal point
Floating Point Constants
You can represent floating point literals either
decimal form or
exponential form
A floating-point literal has
integer part
decimal point
fractional part
exponent part
A single alphabet, a single digit or a single special symbol enclosed within single quotes
Character Constants
The maximum length of a character constant is
1 character
Enclosed within double quotes
String Constants
Contains characters that are similar to character literals:
plain character
escape sequences
Two ways of defining constants
Using #define preprocessor
Using const keyword
Syntax of #define preprocessor
define IDENTIFIER value
Syntax of const keyword
const type variable = value;
Something that acts on a variable or an expression
Operators
Operators does
computes or retrieves a value
changes an object
The symbols which are used to perform logical and mathematical
operations in a C program
Operators
Join individual constants and variables to form expressions
Operators
Operators are used to perform _ and _ operations in a C program
logical and mathematical
Expressions can be _
nested
Types of Operators
Arithmetic operators
Assignment operators
Increment/decrement operators
Relational operators
Logical operators
Conditional operators (ternary operators)
Special operators
Operators that perform +, -, *, /
Arithmetic Operators
require one operand
Unary
require two operands
Binary
% requires _ operands
integer
The / can produce surprising results. When both of the operands are int, the result
truncated
Operator Precedence
Highest + - (unary) * / % Lowest + - (binary)
Left Associative
* / % + -
Right Associative
unary operators ( + - )
The = operator is _ associative
right associative
Can have a value assigned to them
Lvalues
Placed on the left side of an equal sign
Lvalues
Compound Assignment Operators Associativity
right associative
Increment and Decrement Operators
++ (increment)
– (decrement)
used to increase the value of the variable by one
Increment operators (i++, ++i)
used to decrease the value of the variable by on
Decrement operators(i–, –i)
used to decrease the value of the variable by on
Decrement operators(i–, –i)
Value of expression is an incremented/decremented value
++i;
Value of expression is the original value, before it was modified
i++
All binary operators → taking 2 operands
Relational Operators
If the relation is true, it returns
1
If the relation is false, it returns
0
Used to compare values, usually in making decisions
Relational Operators
Relational Operators Precedence
Arithmetic operators have higher priority than relational operators
Relational Operators Associativity
The relational operators are left associative
Equality Operators (equal to)
==
Equality Operators (not equal to)
!=
Equality Operators Associativity
Left associative
Equality Operators produce
True (1) or False (0)
Equality Operators Precedence
lower precedence than relational operators
Logical operators
&& || !
used when more than one conditions are to be tested and based on that
result, decisions have to be made
Logical Operators
Logical AND
&&
Logical OR
||
Logical NOT
!
Logical NOT
!
Logical NOT
!
Logical NOT
!