IT 102: Programming Language Structure, Syntax, Semantics, Keywords, and Identifiers
Course Details
- Course Code & Name: IT 102 – Computer Programming 1
- Topic: Programming Language Structure, Syntax and Semantics, Keywords, and Identifiers
- Instructor: Sitti Mariam M. Jolo
Programming Languages Overview
- Definition: A programming language is a formal system used to write instructions that computers can process.
- Structural Rules: Similar to human languages, programming languages possess specific rules governing code construction. In C++, rules strictly govern:
- Writing statements
- Naming variables
- Using symbols
- Declaring variables
- Defining functions
- Organizing program instructions
- These governing rules form the syntax of C++.
Syntax and Syntax Errors
- Syntax Definition: Syntax refers to the precise rules that determine how symbols, words, and statements must be arranged in a programming language.
- Valid C++ Statement:
cout << "Hello World"; - Invalid C++ Statement:
cout << "Hello World"(Fails because it omits the required statement terminator;).
- Valid C++ Statement:
- Syntax Error Definition: A syntax error occurs when a programmer violates the grammatical rules of the programming language.
- Common Categories of Syntax Errors:
- Missing Semicolon:
- Incorrect:
cout << "Hello" - Correct:
cout << "Hello"; - Missing Quotation Mark:
- Incorrect:
cout << "Hello; - Correct:
cout << "Hello"; - Missing Closing Brace:
- Incorrect:
int main() { cout << "Hello"; - Correct:
int main() { cout << "Hello"; } - Incorrect Capitalization:
- C++ is strictly case-sensitive.
coutis distinct fromCout.- The correct standard output command is lower-case
cout.
Syntax Error Exercises
- Exercise 1: Code
cout<<“Good Morning”- Identified Error: Missing semicolon
;at the end of the statement.
- Identified Error: Missing semicolon
- Exercise 2: Code
Cout<<“Welcome”;- Identified Error: Incorrect capitalization of
Cout(must be lowercasecout).
- Identified Error: Incorrect capitalization of
- Exercise 3: Code
cout << Welcome";- Identified Error: Missing opening double quotation mark
"beforeWelcome.
- Identified Error: Missing opening double quotation mark
- Exercise 4: Code
int main(- Identified Error: Missing closing parenthesis
), opening brace{, and closing brace}.
- Identified Error: Missing closing parenthesis
- Exercise 5: Code
return 0- Identified Error: Missing semicolon
;at the end of the return statement.
- Identified Error: Missing semicolon
Semantics
- Semantics Definition: Semantics refers to the meaning or purpose of a programming statement (what the code actually performs).
- Semantic Evaluation Examples:
- Statement:
int age = 20; - Syntax: Correct C++ declaration and initialization syntax.
- Semantics: Directs the computer to create an integer variable named
ageand assign it the numeric value20. - Statement:
cout << "Welcome"; - Semantics: Directs the computer to display the word
Welcomeon the screen.
- Statement:
Syntax vs. Semantics Comparison

- Comparative Summary Table:
- Syntax:
- Meaning: Rules for writing code.
- Core Question: "Is the code written correctly?"
- Semantics:
- Meaning: Meaning of the code.
- Core Question: "What does the code mean or do?"
- Illustrated Example (
int age = 18;):- Syntax: The statement follows the correct structural syntax of C++.
- Semantics: It creates an integer variable named
agecontaining the value18.
- Diagnostic Exercises (Classifying Syntax vs. Semantics):
- Scenario: A semicolon is missing after a statement. -> Syntax
- Scenario: The formula adds two numbers when it should multiply them. -> Semantics
- Scenario: The opening brace
{has no matching closing brace}. -> Syntax - Scenario: The program calculates an incorrect average. -> Semantics
- Scenario: A quotation mark is missing. -> Syntax
Basic Structure of a C++ Program

Standard Program Template: ```cpp
include
using namespace std;
int main() { cout << "Hello, World!" << endl; return 0; } ```
Detailed Explanation of Core Components:
#include: Preprocessor directive that instructs the preprocessor to include the contents of a header file or library prior to code compilation.<iostream>: Standard Input/Output Stream header file. Provides necessary I/O facilities:cout: Standard character output stream.cin: Standard character input stream.endl: Line ending manipulator used to insert a newline character and flush the stream.using namespace std;: Using-directive. Places standard library names into the global namespace, allowing convenient access without prefixingstd::.int main(): Main function identifier. Serves as the mandatory execution entry point for standard C++ console applications.{ }: Curly braces defining a code block, indicating the start and end of function definitions or statement blocks.cout: Standard output stream object used to send text and data to the console display.<<: Stream insertion operator; directs the right-hand operand into the output stream."Hello, World!": Text contained within double quotation marks, categorized as a string literal.;: Semicolon serving as the required statement terminator.return 0: Return statement that terminates themain()function and yields the integer status code0to the operating system (0signals success).
Program Structure Analysis

- Component Classification Table:
#include <iostream>— Preprocessor directiveiostream— Standard input/output headerusing namespace std;— Allows convenient access to names instdint— Keyword / data typemain— Main function identifier{ }— Defines a blockcout— Standard output stream<<— Stream insertion operator"Hello, World!"— String literal;— Statement terminatorreturn— Keyword0— Integer literal
Comments in C++

- Definition: Comments are explanatory notes written within the source code strictly for developers.
- Compiler Treatment: Comments are completely ignored by the C++ compiler during execution.
- Comment Styles:
- Single-line Comments: Denoted by
//(e.g.,// Hello). - Multi-line Comments: Enclosed between
/*and*/(e.g.,/* This is a Multiple line Comment */).
- Single-line Comments: Denoted by
Keywords
- Definition: Reserved words that possess explicit, predefined meanings within the C++ programming language.
- Usage Constraint: C++ keywords cannot be used as custom programmer-defined identifiers.
- List of C++ Keywords:
intreturnifelsewhilefordoublefloatcharboolvoidswitchCasebreakcontinueclasspublicprivate
Identifiers and Rules
- Definition: Custom identifiers created by the programmer to name program elements.
- Identifier Uses: Variables, functions, classes, arrays, objects, and other user-defined entities.
- Examples:
age,studentName,totalScore,averageGrade,calculateTotal. - Six Standard Rules for C++ Identifiers:
- Rule 1: May Contain Letters
- Valid:
student,total,average. - Rule 2: May Contain Numbers, but Cannot Begin with a Number
- Valid:
student1,score2,grade2026. - Invalid:
1student,2score,2026grade. - Rule 3: May Contain an Underscore (
_) - Valid:
student_name,total_score,first_name. - Rule 4: Spaces Are Prohibited
- Invalid:
student name,total score. - Rule 5: Keywords Cannot Be Used as Identifiers
- Invalid:
int return;,int for;,int class;(sincereturn,for, andclassare reserved keywords). - Rule 6: C++ Identifiers Are Case-Sensitive
score,Score, andSCORErepresent three completely distinct identifiers.- Mixing cases arbitrarily creates confusion and logical/syntax errors.
Literals
- Definition: A literal is a fixed value written directly into the source code.
- Categories and Examples:
- Integer Literal:
25 - Decimal Literal:
95.5 - Character Literal:
'A' - String Literal:
"Computer Programming" - Boolean Literal:
true,false
- Integer Literal:
- Literal Analysis Example (
int age = 20;):int: Keyword (data type specifier)age: Identifier (variable name)=: Assignment operator20: Integer literal;: Statement terminator
Statements

- Definition: A statement is a single complete instruction executed in a C++ program.
- Examples:
int age = 20;,cout << "Hello";,return 0;. - Statement Classification Table:
#include <iostream>— Preprocessor directiveusing namespace std;— Using-directiveint age = 20;— Declaration/initialization statementcout << "Hello";— Output statement / expression statementreturn 0;— Return statement// Hello— Comment
References
- Course Syllabus and CCS Student Handbook
- CMO No. 25, series of 2015
- Zak, D. (2009). An Introduction to Programming with C++
- Ahmad, S. S. (2024). Fundamentals of Programming
- Downey, A. B. (n.d.). Think C++: How to think like a computer scientist. Green Tea Press
- James, Jason (2026). Exploring C++: The Adventure Begins
- Soulie, Juan (2007). C++ Language Tutorial