Module 2
Module 2
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.
III.DISCUSSION:
Engineering-Computing Academy of
Science and Technology
BSIT
What is C?
It is a very popular language, despite being old. The main reason for its
science.
operating system.
Why Learn C?
programming languages such as Java, Python, C++, C#, etc, as the syntax
is similar
Python
The main difference between C and C++ is that C++ supports classes and
A compiler, like GCC, to translate the C code into a language that the
There are many text editors and compilers to choose from. In this lesson, we will
use an IDE.
What is an IDE?
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.
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
What is a SYNTAX?
In C programming, the term "syntax" refers to the set of rules laid down for the
Example:
Line 1: #include
<stdio.h> is a
allows us to work
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
where the program begins execution. Any code inside the curly brackets {} of
Line 4: The printf() function is used to display text on the screen. In this
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()
C STATEMENTS
statements. The following statement "instructs" the compiler to print the text
If you forget the semicolon (;), an error will occur and the program will not run.
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 " ".
You can use as many printf() functions as you want. However, note that it does
NEW LINES
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
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).
C Multi-line Comments
What is a Variable?
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
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
123
19.99
Where type is one of C types (such as int), and variableName is the name of the
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.
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 different types in a single printf() function, you can use the following:
You can also just print a value without storing it in a variable, as long as you use
the correct format specifier:
If you assign a new value to an existing variable, it will overwrite the previous
value:
Engineering-Computing Academy of
Science and Technology
BSIT
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
III. ASSESSMENT:
Reference List:
C - Basic Syntax. (n.d.). https://www.tutorialspoint.com/cprogramming/c_basic_syntax.htm
basic-syntax/
S, H. S. (2024, July 23). The One-Stop Solution To Learn Everything You Need To Know About
variables-in-c#:~:text=In%20C%20programming%20language%2C%20a,times%20during
%20the%20program%20execution.
What is an IDE? - Integrated Development Environment Explained - AWS. (n.d.). Amazon Web
10! = 10x9 = 90
8! =