SRG
Programming 1
BSIT 1-1
Rafael Joar Parungao
September 27, 2024 | September 29, 2024
Questions about
the past lesson?
developer (weh)
bsit 4-1
Hi! Ako si Kuya Raf
mahilig sa kape
nakasurvive ng C programming
freelance developer
Basic Program
Structure
C Language
Learning Objectives!
To recount the beginnings of the C Language.
To design algorithms to solve problems.
To know and apply the various elements in
program development.
To know and apply the various syntax and
semantics of the C Language.
To distinguish and differentiate the various
functions of the C Language.
Introduction
C is a general-purpose programming language
which features economy of expression, modern control
flow and data structures and a rich set of operations.
It is also called a “System Programming Language”
because it is useful for writing compilers and operating
systems.
History of C
1972: Designed by Dennis Ritchie at AT&T Bell Labs.
1970: Developed from B language by Ken Thompson for UNIX.
BCPL: A predecessor of B language.
1987: Borland developed Turbo C for MS-DOS.
Features of C
General-purpose Portable and supports Middle-level language Efficient in system-level
language structured programming. combining high-level and programming and
assembly language manipulation of bits and
elements. bytes.
Basic Structure of C programs
Consists of one or more functions.
A function has a name and a body enclosed in
curly braces { }.
Every C program must contain one main() function.
Statements end with a semicolon.
Definition of Terms
Source code – A program - the text of a program that
a user can read.
Object code - a translation of the program source
code in a form that can be directly executed by the
computer.
Interpreter – reads the source code of your program
one line at a time and performs the specific instructions
contained in that line.
Compiler – reads the entire program and converts it
into object code.
Compile Time – refers to the events that occur during
the compilation process.
Definition of Terms (Cont.)
Run Time - refers to the events that occur while the
program is actually executing.
Library – collection of pre-written standard functions.
Syntax error – an error detected during compile time.
Semantic/Run Time error – an error detected during
execution time.
Levels of Programming Language
Machine Level Assembly Level High Level
Binary code. Low-level, symbolic code. Close to human language (e.g.,
C, Python).
The Programming
Process
Components of Turbo C
1. Editor – used to create program source code.
2. Compiler
3. Debugger – used for testing program and locating
programming errors
4. Run-Time Environment
5. User Interface
Types of words in C
Reserved Words User-defined Words
are words set aside for the C Language are words/identifiers used by the
programmer to create a program.
Identifiers
names that are used to reference variables, functions,
labels and various user-defined objects
Rules for Identifiers
a. Must start with a letter followed by a combination of
letters and or numbers. Significant length is up to 32
characters.
b. Only allowed special character is the underscore ( _ ).
c. Case sensitive.
d. Must not be the same as the Turbo C reserved words.
Interactive Input/Output Statements
names that are used to reference variables, functions,
labels and various user-defined objects
Using pre-processing
directives
The C compiler has a pre-processor built into it. Lines that
begin with a # are called Preprocessing directives
The #include is a preprocessing directive that causes a
copy of the file to be included at this point in the file when
compilation occurs. An include file is also called a header
file. By convention, the names of header files end in .h.
Input Statement
The scanf() function is the function to input a value to a
variable.
Syntax:
scanf(<format specifier>, variable);
Format Specifier/Conversion Character
Output Statement
The printf() function is used for output. The “f” in printf()
stands for “formatted”.
Syntax:
1. printf(“<string to be displayed”);
2. printf(“format specifier”, variable);
Escape character sequence
a combination of characters that represents a special character or action that cannot be easily
expressed within the normal character set.
Operators and Expressions
Operator is a symbol that performs a mathematical or
logical operation.
Expression is a mixture/set of constants and operators
which evaluates to a certain value
3 General Classes of Operators
1. Arithmetic
2. Relational
3. Logical
Arithmetic Operators
Positive value indicator. Negates operand value.
Multiplies two numbers.
Divides two numbers.
Remainder of division.
Adds two numbers.
Subtracts two numbers.
Increases value by one.
Decreases value by one.
Increment & Decrement
Operators
1. Pre-increment ++x
2. Post-increment x++
3. Pre-decrement --x
4. Post-decrement x—
Types of Arithmetic Operators
1. Unary operator – require only a
single operand like a unary plus and
unary minus.
2. Binary operator – operators that
require two operands. Ex. X+Y
3. Combined operators – C’s
shorthand operation
Arithmetic Operators (cont.)
Note!
In evaluating arithmetic expressions, the Parenthesis
Multiplication Division Addition Subtraction ( PMDAS) is
used.
Rational Operators
Relational operators are used to compare 2 expressions.
It should evaluate to a logical value either TRUE or FALSE
Logical Operators
Q&A