Professional Documents
Culture Documents
L5a C Programs PDF
L5a C Programs PDF
ddobach 2
Refers to values that do not change
throughout the execution of the program
◦ Integer constants
◦ Real (floating point) constants
◦ Character constants
◦ String constants
ddobach 3
Integer valued number
Ex: 123 -456 0 +5
Can be written in decimal[base 10], octal
[base 8], or hexadecimal [base 16]
◦ Octal: first digit must be 0 (ex: 037)
◦ Hexadecimal: first digit must be 0x or 0X
(ex: 0x2, 0X2, 0xB)
ddobach 4
Numbers with fractional parts
Ex: 3.1416
Must have at least one digit
Must have a decimal point
Can either be positive or negative
Default sign is positive
No commas or blank spaces allowed
ddobach 5
The mantissa part and the exponential part
must be separated by a letter e.
Mantissa part may be positive or negative
Default sign is positive
Exponent part must contain at least one digit
Ex: 0.65e4 1.5e+5
ddobach 6
Single character enclosed in single quotes
Represent integer values known as ASCII
values hence it is also possible to perform
arithmetic operations on character constants
Ex: ‘a’ ‘6’ ‘.’
ddobach 7
Sequence of characters enclosed in double
quotes
Characters may be letters, numbers, special
characters, or blank space
Ex: “hello” “1986” “…Hi”
“1+1”
ddobach 8
Words which carry a specific meaning and
serve as a specific building block for program
statements
Cannot be used as variable names
Ex: auto break case char const
continue default do double else
enum float for goto if
int
ddobach 9
Used in C programs to declare variables,
functions, and constants to handle storage
representations and machine instructions
◦ int integer; a whole number
◦ float floating point number; number with
fractional part
◦ double a double-precision floating point value
◦ char a single character
ddobach 10
Has data type and a name
Can either be local variable or global variable
Local variables : can be used inside the
function it is declared starting
from the point where it is
declared
Global variables: known throughout the entire
program
ddobach 11
Refer to fixed values that may not be altered
by the program
All the previous data types can be defined as
constant data types
Must be defined before the main function
ddobach 12
ddobach 13
Arithmetic Operators
Relational Operators
Logical Operators
Assignment Operators
Increment and Decrement Operators
Conditional Operators
ddobach 14
Addition (+)
◦ a+b adds a and b
Subtraction (-)
◦ a–b subtracts b from a
Multiplication (*)
◦ a*b multiplies a and b
Division (/)
◦ a/b divides a by b
Modulo (%)
◦ a%b returns the remainder when dividing a by b
ddobach 15
Symbol Meaning
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Equal to
!= Not equal to
ddobach 16
Basic expression for a logical expression is:
X1 op X2
Where x1, x2 can be boolean expressions,
variables, or constants and op is an
operator
The following truth tables summarize the
result for each operation for all possible
combinations of x1 and x2.
ddobach 17
x1 x2 result
TRUE TRUE TRUE
TRUE FALSE FALSE
FALSE TRUE FALSE
FALSE FALSE FALSE
ddobach 18
x1 x2 result
TRUE TRUE TRUE
TRUE FALSE TRUE
FALSE TRUE TRUE
FALSE FALSE FALSE
ddobach 19
x1 result
TRUE FALSE
FALSE TRUE
ddobach 20
Used to assign values of an expression to a
variable
Ex: number = 10;
ddobach 21
Used for incrementing or decrementing a
value of a variable by 1
Ex: a++ b—
Operator Function
ddobach 22
The following are equal:
a=a+1
a++
a += 1
ddobach 23
Syntax: expr1?expr2:expr3
ddobach 24
end
ddobach 25