Professional Documents
Culture Documents
Lesson 3:
C Language-Part2
Prepared by:
Prof. Marienel N. Velasco
Unit
Pg. 1
I’m going to talk about
vData Types
vInput/Output
vOperators
Alphabets
Digits
Unit
Pg. 3
Keywords and Identifiers
Special
Characters
White space
blank space, new line, horizontal tab, carriage return and form
Characters
feed
Unit
Pg. 5
Keywords and Identifiers
Unit
Pg. 6
Keywords and Identifiers
Rules for writing 1. A valid identifier can have letters (both uppercase and
an identifier lowercase letters), digits and underscores.
2. The first letter of an identifier should be either a letter or an
underscore. However, it is discouraged to start an identifier
name with an underscore.
3. There is no rule on length of an identifier. However, the first
31 characters of identifiers are discriminated by the
compiler.
Unit
Pg. 7
Constants and Variables
Unit
Pg. 8
Constants and Variables
Unit
Pg. 9
Constants and Variables
2. Floating-point constants
A floating point constant is a numeric constant that has either
a fractional form or an exponent form. For example:
Unit
Pg. 11
Constants and Variables
4. Escape Sequences
Sometimes, it is necessary to use characters which cannot be
typed or has special meaning in C programming. For example:
newline(enter), tab, question mark etc. In order to use these
characters, escape sequence is used.
Unit
Pg. 12
Constants and Variables
Different
types
of Constants
Unit
Pg. 13
Constants and Variables
6. Enumeration constants
Keyword enum is used to define enumeration types. For
example:
Integers are whole numbers that can have both positive and
int - Integer negative values but no decimal values. Example: 0, -5, 10
data types In C programming, keyword int is used for declaring integer
variable. For example:
float - Floating Floating type variables can hold real numbers such as: 2.34, -
types 9.382, 5.0 etc. You can declare a floating point variable in C by
using either float or double keyword. For example:
Difference The size of float (single precision float data type) is 4 bytes.
between float and And the size of double (double precision float data type) is 8
double bytes. Floating point variables has a precision of 6 digits
whereas the precision of double is 14 digits.
char - Character Keyword char is used for declaring character type variables.
types For example:
C Qualifiers Qualifiers alters the meaning of base data types to yield a new
data type.
Unit
Pg. 17
Data Types
Size qualifiers alters the size of a basic type. There are two size
Size qualifiers qualifiers, long and short. For example:
Sign qualifiers Integers and floating point variables can hold both negative and
positive values. However, if a variable needs to hold positive
value only, unsigned data types are used. For example:
Volatile qualifiers A variable should be declared volatile whenever its value can
be changed by some external sources outside the program.
Keyword volatile is used for creating volatile variables.
Unit
Pg. 19
C Input Output (I/O)
Output
Unit
Pg. 20
C Input Output (I/O)
Example #2:
C Integer Output
Unit
Output Pg. 21
C Input Output (I/O)
Example #3:
C Integer
Input/Output
Output
Unit
Pg. 22
C Input Output (I/O)
Example #4:
C Floats
Input/Output
Output
Unit
Pg. 23
C Input Output (I/O)
Example #5: C
Character I/O
Output
Unit
Pg. 24
C Input Output (I/O)
Little bit on ASCII When a character is entered in the above program, the
code character itself is not stored. Instead, a numeric value(ASCII
value) is stored.
And when we displayed that value using “%c” text format, the
entered character is displayed.
Example #6:
C ASCII Code
Output
Enter a character: g You entered g. ASCII value of g is
103. The ASCII value of character 'g' is 103. When, 'g'
is entered, 103 is stored in variable var1 instead of g.
Unit
Pg. 25
C Operators
Unit
Pg. 26
C Operators
C Arithmetic
Operators
Unit
Pg. 27
C Operators
Example #7:
Arithmetic
Operators
Output
Unit
Pg. 28
C Operators
Example #8:
Increment
and
Decrement
Operators
Unit
Pg. 29
C Operators
Unit
Pg. 30
C Operators
Example #9:
Assignment
Operators
Unit
Pg. 31
C Operators
C Relational
Operators
Unit
Pg. 32
C Operators
Example #10:
Relational
Operators
Unit
Pg. 33
C Operators
C Logical
Operators
Unit
Pg. 34
C Operators
Example #11:
Logical Operators
Unit
Pg. 35
C Operators
Example #12:
Logical Operators
Explanation of
logical operator
program
Unit
Pg. 36
C Operators
Bitwise Operators
Unit
Pg. 37
C Operators
Other Operators
Example #6:
sizeof Operator
Unit
Pg. 38
C Operators
Unit
Pg. 39
C Operators
Example #13:
C conditional
Operator
Unit
Pg. 40
C Introduction Examples
Program to Print
an Integer
Unit
Pg. 41
C Introduction Examples
C Program to Add
Two Integers
UnitPg. 42
C Introduction Examples
Program to Print
ASCII Value
UnitPg. 43
C Introduction Examples
Program to
Compute
Quotient
and Remainder
UnitPg. 44
C Introduction Examples
Program to Find
the Size of a
variable
UnitPg. 45
That’s all folks!
Unit
Pg. 46