Engineering-Computing Academy of
Science and Technology
BSIT
Course Code CCC 112 A
Course Description Introduction to Computer Programming 1
Module Title Introduction to the C Language
I. INTRODUCTION:
Introduction to C Programming lays the groundwork for understanding one of the most
influential programming languages in computer science. Created by Dennis Ritchie in
1972, C provides a powerful yet straightforward syntax that serves as the foundation for
many modern languages, including C++, Java, and Python. Key concepts such as
program structure, syntax rules, variables, and data types enable developers to write
efficient and versatile code. Widely used in system programming, application
development, and embedded systems, learning C equips programmers with the skills to
solve complex problems and build scalable solutions in various fields.
II. PRE- DISCUSSION ACTIVITY:
III.DISCUSSION:
Engineering-Computing Academy of
Science and Technology
BSIT
CHAPTER 2.1 History of C
What is C?
C is a general-purpose programming language created by Dennis Ritchie
at the Bell Laboratories in 1972.
It is a very popular language, despite being old. The main reason for its
popularity is because it is a fundamental language in the field of computer
science.
C is strongly associated with UNIX, as it was developed to write the UNIX
operating system.
Why Learn C?
It is one of the most popular programming languages in the world
If you know C, you will have no problem learning other popular
programming languages such as Java, Python, C++, C#, etc, as the syntax
is similar
C is very fast, compared to other programming languages, like Java and
Python
C is very versatile; it can be used in both applications and technologies
Engineering-Computing Academy of
Science and Technology
BSIT
Difference between C and C++
C++ was developed as an extension of C, and both languages have
almost the same syntax
The main difference between C and C++ is that C++ supports classes and
objects, while C does not.
Get Started With C
To start using C, you need two things:
A text editor, like Notepad, to write C code
A compiler, like GCC, to translate the C code into a language that the
computer will understand
There are many text editors and compilers to choose from. In this lesson, we will
use an IDE.
What is an IDE?
An integrated development environment (IDE) is a software application that
helps programmers develop software code efficiently. It increases developer
productivity by combining capabilities such as software editing, building, testing,
and packaging in an easy-to-use application. Just as writers use text editors and
Engineering-Computing Academy of
Science and Technology
BSIT
accountants use spreadsheets, software developers use IDEs to make their job
easier.
An IDE (Integrated Development Environment) is used to edit AND compile the
code. Popular IDE's include Code::Blocks, Eclipse, and Visual Studio. These are
all free, and they can be used to both edit and debug C code. Web-based IDE's
can work as well, but functionality is limited.
CHAPTER 2.2 Structure of C Program
What is a SYNTAX?
In C programming, the term "syntax" refers to the set of rules laid down for the
programmer to write the source code of a certain application. While there is a
specific syntax recommended for each of the keywords in C, certain general
rules need to be followed while developing a program in C.
Engineering-Computing Academy of
Science and Technology
BSIT
Example:
Line 1: #include
<stdio.h> is a
header file that
allows us to work
with input and
output functions, such as printf() (used in Line 4).
Header files provide additional functionality to C
programs.
Note: Don't worry if you don't fully understand how #include <stdio.h> works yet.
For now, just think of it as something that (almost) always appears in your
program.
Line 2: This is a blank line. While C ignores white spaces, programmers use
them to make the code more readable.
Line 3: The main() function is another essential part of a C program. This is
where the program begins execution. Any code inside the curly brackets {} of
main() will be executed.
Engineering-Computing Academy of
Science and Technology
BSIT
Line 4: The printf() function is used to display text on the screen. In this
example, it outputs the text: "Hello World!".
Important: Every C statement ends with a semicolon (;).
Line 5: return 0; ends the main() function and indicates that the program has
executed successfully.
Line 6: The closing curly bracket {} is used to indicate the end of the main()
function. Do not forget to include it!
C STATEMENTS
What are Statements in C Language?
A computer program is a list of "instructions" to be "executed" by a computer. In
a programming language, these programming instructions are called
statements. The following statement "instructs" the compiler to print the text
"Hello World" to the screen:
Engineering-Computing Academy of
Science and Technology
BSIT
It is important that you end the statement with a semicolon ;
If you forget the semicolon (;), an error will occur and the program will not run.
CHAPTER 2.3 C Output (Print Text)
OUTPUT (PRINT TEXT)
To output values or print text in C, you can use the printf() function:
DOUBLE QUOTES
When you are working with text, it must be wrapped inside double quotations
marks " ".
If you forget the double quotes, an error occurs:
Engineering-Computing Academy of
Science and Technology
BSIT
MANY PRINTF FUNCTIONS
You can use as many printf() functions as you want. However, note that it does
not insert a new line at the end of the output:
NEW LINES
To insert a new line, you can use the \n character:
C COMMENTS
Engineering-Computing Academy of
Science and Technology
BSIT
Comments in C
Comments can be used to explain code, and to make it more readable. It can
also be used to prevent execution when testing alternative code.
Comments can be singled-lined or multi-lined.
Single-line Comments
Single-line comments start with two forward slashes (//). Any text between // and
the end of the line is ignored by the compiler (will not be executed).
This example uses a single-line comment before a line of code:
C Multi-line Comments
Multi-line comments start with /* and ends with */.
Any text between /* and */ will be ignored by the compiler:
Engineering-Computing Academy of
Science and Technology
BSIT
CHAPTER 2.4 C Variables
What is a Variable?
In C programming language, a variable is a user-defined or a user-readable
custom name assigned to a memory location. Variables hold a value that can be
modified and reused many times during the program execution. A variable can
be an alphabet or digits and start with an underscore, but you cannot declare a
keyword as a variable name.
Variables are containers for storing data values, like numbers and characters.
In C, there are different types of variables (defined with different keywords), for
example:
Engineering-Computing Academy of
Science and Technology
BSIT
int - stores integers (whole numbers), without decimals, such as 123 or -
123
float - stores floating point numbers, with decimals, such as 19.99 or -
19.99
char - stores single characters, such as 'a' or 'B'. Characters are
surrounded by single quotes
Declaring (Creating) Variables
To create a variable, specify the type and assign it a value:
Where type is one of C types (such as int), and variableName is the name of the
variable (such as x or myName). The equal sign is used to assign a value to
the variable.
Engineering-Computing Academy of
Science and Technology
BSIT
So, to create a variable that should store a number, look at the following
example:
You can also declare a variable without assigning the value, and assign the
value later:
In many other programming languages (like Python, Java, and C++), you would
normally use a print function to display the value of a variable. However, this is
not possible in C:
Engineering-Computing Academy of
Science and Technology
BSIT
Format Specifiers
Format specifiers are used together with the printf() function to tell the compiler
what type of data the variable is storing. It is basically a placeholder for the
variable value.
A format specifier starts with a percentage sign %, followed by a character.
For example, to output the value of an int variable, use the format
specifier %d surrounded by double quotes (""), inside the printf() function:
To print other types,
use %c for char and %f for float:
To combine both text and a
variable, separate them with a comma inside the printf() function:
Engineering-Computing Academy of
Science and Technology
BSIT
To print different types in a single printf() function, you can use the following:
Print Values Without Variables
You can also just print a value without storing it in a variable, as long as you use
the correct format specifier:
Change Variable Values
If you assign a new value to an existing variable, it will overwrite the previous
value:
Engineering-Computing Academy of
Science and Technology
BSIT
You can also assign the value of one variable to another:
Add Variables Together
To add a variable to another variable, you can use the + operator:
Engineering-Computing Academy of
Science and Technology
BSIT
Declare Multiple Variables
To declare more than one variable of the same type, use a comma-
separated list:
C Variable Names
All C variables must be identified with unique names. These unique names
are called identifiers. Identifiers can be short names (like x and y) or more
descriptive names (age, sum, totalVolume). It is recommended to use descriptive
names in order to create understandable and maintainable code:
The general rules for naming variables are:
Names can contain letters, digits and underscores
Names must begin with a letter or an underscore (_)
Names are case-sensitive (myVar and myvar are different variables)
Names cannot contain whitespaces or special characters like !, #, %, etc.
Reserved words (such as int) cannot be used as names
Engineering-Computing Academy of
Science and Technology
BSIT
III. ASSESSMENT:
Reference List:
C - Basic Syntax. (n.d.). https://www.tutorialspoint.com/cprogramming/c_basic_syntax.htm
GeeksforGeeks. (2023, June 16). C Basic Syntax. GeeksforGeeks. https://www.geeksforgeeks.org/c-
basic-syntax/
S, H. S. (2024, July 23). The One-Stop Solution To Learn Everything You Need To Know About
Variables In C. Simplilearn.com. https://www.simplilearn.com/tutorials/c-tutorial/what-is-
variables-in-c#:~:text=In%20C%20programming%20language%2C%20a,times%20during
%20the%20program%20execution.
W3Schools.com. (n.d.). https://www.w3schools.com/c/c_variables_reallife.php
What is an IDE? - Integrated Development Environment Explained - AWS. (n.d.). Amazon Web
Services, Inc. https://aws.amazon.com/what-is/ide/
Prepared by: Reviewed by: Recommending Approved:
Approval:
Justin Nichol P. Dr. Jane M. Virgo C. Lopez, PhD Donna Padilla
Pasamonte Fernandez Vice President for Taguiba, PhD
Faculty,E-Coast Dean,E-Coast Academics President
Engineering-Computing Academy of
Science and Technology
BSIT
10! = 10x9 = 90
8! =