LESSON 7
THE CASE STUDY
Page 02
LEARNING COMPETENCIES
Check programming activities with the
development plan [TLE_ICTCP9-12PDIVf-j-2]
Present program deliverables to appropriate
person for approval [TLE_ICTCP9-12PDIVf-j-2]
Page 02
LEARNING OBJECTIVES
Define pointers, arrays, and strings in the
context of C programming.
Implement a simple C program using
pointers, arrays, and strings that aligns with
a given development plan
Design a C program using pointers, arrays,
and strings that fulfills specific development
plan requirements.
Page 02
7.1
Introduction
to
Pointers
About us
studio shodwe Home Startegy
Page 03
What is a Pointer?
A pointer is a variable that holds the memory address of another variable.
Instead of storing data directly, pointers store the location of data in
memory.
Key Points:
•A pointer doesn't hold the data itself but the address where the data is stored.
•Pointers are fundamental in C for dynamic memory allocation, arrays, and
working with functions efficiently.
Definition:
About us
studio shodwe Home Startegy Contact
Page 04
Understanding Memory Addresses
•Memory Address:
Every variable in C is stored at a specific memory
location, which can be identified by its memory
address.
•How to Visualize:
Imagine the computer's memory as a series of
boxes (memory cells). Each box has a unique
address, and variables are stored in these boxes.
About us
studio shodwe Home Startegy Contact
Page 05
Pointer Example:
About us
studio shodwe Home Startegy Contact
Page 06
Declaring the Pointer
About us
studio shodwe Home Startegy Contact
Page 06
Note:
A pointer must always be declared with the data type it points to, as it
ensures correct pointer arithmetic and type safety.
About us
studio shodwe Home Startegy Contact
Page 06
About us
studio shodwe Home Startegy Contact
Address Operator (&)
The address operator is used to obtain the memory address of a
variable.
•Example:
Explanation:
•&x gives the memory address of the variable x.
•The pointer p stores this address.
About us
studio shodwe Home Startegy Contact
Page 06
Page 08
Pointer Expressions and Arithmetic
•Pointer Arithmetic:
•Pointers are not just variables, but they can be manipulated
mathematically.
•You can perform arithmetic operations like increment (++), decrement (--),
addition (+), and subtraction (-) on pointers.
How Pointer Arithmetic Works:
•When you increment a pointer, it moves by the size of the type it points to.
For example, if p is an int *, then p++ will move it by size of(int) bytes.
Page 08
Example:
Pointers and Arrays:
•The name of an array is actually a pointer to its first element.
•You can manipulate arrays using pointers.
About us
studio shodwe Home Startegy Contact
Page 06
Pointers and Functions
•Call by Value:
•Definition: In call by value, a copy of the variable is passed to the function.
Changes made inside the function do not affect the original variable.
•Example:
About us
studio shodwe Home Startegy Contact
Page 06
Call by Reference:
•Definition: In call by reference, a pointer to the variable is passed to the function.
This means changes inside the function affect the original variable.
•Example:
Why Use Call by Reference:
•It allows you to modify the actual
value of the arguments passed.
•It is useful when you need to return
multiple values or work with large data
structures efficiently.
Key Differences Between Call by Value and Call by Reference
About us
studio shodwe Home Startegy Contact
Page 06
Page 02
7.2
Introduction
to
ARRAYS
About us
studio shodwe Home Startegy
Page 03
What is an Array?
Definition:
An array is a collection of variables of the same data type that are stored in contiguous
memory locations. Arrays are used to store multiple values under a single name, and you
can access each element of the array using an index.
•Key Points:
•Arrays are indexed starting from 0.
•All elements in an array must be of the same data type (e.g., all ints, all chars, etc.).
•The size of an array is fixed once it is declared.
Array Declaration
•Syntax for Declaring an Array:
•type: The data type of the array elements (e.g., int, float, char).
•array_name: The name of the array variable.
•size: The number of elements in the array (must be a constant value).
Example of Array Declaration
Explanation:
•arr[5]: This declares an array of 5 integers.
•name[20]: This declares an array to store 20 characters (often used for strings in C).
•scores[10]: This declares an array of 10 floats.
Accessing Array Elements
•Accessing Individual Elements: Array elements are accessed using indices
(starting from 0):
About us
studio shodwe Home Startegy Contact
Page 06
Array Initialization
•Definition:
Initialization is the process of assigning values to the elements of the array
at the time of declaration.
•Syntax for Initialization:
Partial Initialization:
•If not all elements are initialized, the uninitialized elements will automatically be set to 0.
String Initialization:
A string in C is an array of characters, and it is typically initialized with the string literal.
int arr[5] = {10, 20}; // Only the first two elements are initialized; rest will be 0
// arr = {10, 20, 0, 0, 0}
Default Initialization Values
•Default Values:
•For integer arrays: uninitialized elements default to 0.
•For character arrays: uninitialized elements default to '0' (null character).
•For float/double arrays: uninitialized elements default to 0.0.
Array Initialization Example
•Example 1: Integer Array Initialization:
Example 2: String Initialization:
Example 3: Float Array Initialization:
C
float scores[3] = {95.5, 87.2}; // Third element is automatically initialized to 0.0
// scores = {95.5, 87.2, 0.0}
About us
studio shodwe Home Startegy Contact
Page 06
Multi-Dimensional Arrays
•Definition:
A multi-dimensional array is an array of arrays. It can be thought of as a table with rows
and columns.
This creates a 2x3 matrix, where matrix[0][0] = 1, matrix[0][1] = 2, etc.
Accessing Elements:
About us
studio shodwe Home Startegy Contact
Page 06
About us
studio shodwe Home Startegy Contact
Page 06
Page 02
As a group, implement a simple C program utilizing
pointers, arrays, and strings using the C Coding
APP or any other platform. The group's program
must be debugged, and another group will be
responsible for troubleshooting it. Provide the
answer key if necessary. The program must be
fixed before the end of the class. Follow the
troubleshooting format for the debugged program,
ensuring that fixes are made for the specific line
indicated by the group. Provide 10 errors for it.
GROUP TASK: GROUP CODEFIX
Page 02
In Yellow Pad paper follow this
format:
Answer format:
ERROR- LINE-:
FIX :
Page 02
In Yellow Pad paper follow this
format:
Answer format:
ERROR- LINE-:
FIX :
Rubrics
CRITERIA DESCRIPTION SCORE
Program Structure &
Syntax (10 Points)
The program follows correct syntax for pointers,
arrays, and strings.
Debugging Skills
(10 Points)
The group demonstrates effective debugging
techniques. Identifies and fixes all errors in the
program
Peer Troubleshooting (10 Points) Groups demonstrate clear communication when
explaining the debugging process.
Teamwork
(10 Points)
The group actively collaborates, helping others
troubleshoot the program
Answer Key / Documentation
(10 Points)
The answer key includes proper explanations for any
changes made to the original program.
TOTAL 50
Page 02
7.3
Introduction
to
STRING
What is <string.h>?
Definition:
The <string.h> header file in C provides functions for
manipulating C-style strings (arrays of characters).
Common Operations:
•Comparing strings
•Concatenating strings
•Copying strings
•Measuring string lengths
•Searching for characters in strings
Syntax:
String Manipulation:
The functions in <string.h> are essential for working with null-terminated
character arrays (C-strings).
strcmp Function - Comparing Strings
NOTE:
Lexicographic order is a method
of ordering elements in programming
languages based on their alphabetical or
numerical order.
strcmp Function - Comparing Strings
strcmp Function - Comparing Strings
strcmp Function-Concatenating string
Concatenation is the process of combining or joining
two or more strings, text fragments, or variables
together into a single string.
strcmp Function-Concatenating string
strcmp Function-Concatenating string
strcpy Function-Copying string
strcpy Function-Copying string
strcpy Function-Copying string
strlen Function-Finding length of a string
strlen Function-Finding length of a string
strlen Function-Finding length of a string
strrchr Function - Finding Last Occurrence of a Character
strrchr Function - Finding Last Occurrence of a Character
strlen Function-Finding length of a string
Page 02
QUESTIONS???
Page 02
As a group, design a simple C program utilizing
pointers, arrays, and strings using the C Coding APP
or any other platform. The group's program must be
debugged, and another group from the other section
will be responsible for troubleshooting it. Provide
the answer key if necessary. The program must be
fixed before the end of the class. Follow the
troubleshooting format for the debugged program,
ensuring that fixes are made for the specific line
indicated by the group. Provide 20 errors for it.
PROGRAMMING TASK: C Program Fix-Up Challenge
Page 02
In Yellow Pad paper follow this
format:
Answer format:
ERROR- LINE-:
FIX :

Lesson 7-computer programming case study-FINAL.pptx

  • 1.
  • 2.
    Page 02 LEARNING COMPETENCIES Checkprogramming activities with the development plan [TLE_ICTCP9-12PDIVf-j-2] Present program deliverables to appropriate person for approval [TLE_ICTCP9-12PDIVf-j-2]
  • 3.
    Page 02 LEARNING OBJECTIVES Definepointers, arrays, and strings in the context of C programming. Implement a simple C program using pointers, arrays, and strings that aligns with a given development plan Design a C program using pointers, arrays, and strings that fulfills specific development plan requirements.
  • 4.
  • 5.
    About us studio shodweHome Startegy Page 03 What is a Pointer? A pointer is a variable that holds the memory address of another variable. Instead of storing data directly, pointers store the location of data in memory. Key Points: •A pointer doesn't hold the data itself but the address where the data is stored. •Pointers are fundamental in C for dynamic memory allocation, arrays, and working with functions efficiently. Definition:
  • 6.
    About us studio shodweHome Startegy Contact Page 04 Understanding Memory Addresses •Memory Address: Every variable in C is stored at a specific memory location, which can be identified by its memory address. •How to Visualize: Imagine the computer's memory as a series of boxes (memory cells). Each box has a unique address, and variables are stored in these boxes.
  • 7.
    About us studio shodweHome Startegy Contact Page 05 Pointer Example:
  • 8.
    About us studio shodweHome Startegy Contact Page 06 Declaring the Pointer
  • 9.
    About us studio shodweHome Startegy Contact Page 06 Note: A pointer must always be declared with the data type it points to, as it ensures correct pointer arithmetic and type safety.
  • 10.
    About us studio shodweHome Startegy Contact Page 06
  • 11.
    About us studio shodweHome Startegy Contact Address Operator (&) The address operator is used to obtain the memory address of a variable. •Example: Explanation: •&x gives the memory address of the variable x. •The pointer p stores this address.
  • 12.
    About us studio shodweHome Startegy Contact Page 06
  • 13.
    Page 08 Pointer Expressionsand Arithmetic •Pointer Arithmetic: •Pointers are not just variables, but they can be manipulated mathematically. •You can perform arithmetic operations like increment (++), decrement (--), addition (+), and subtraction (-) on pointers. How Pointer Arithmetic Works: •When you increment a pointer, it moves by the size of the type it points to. For example, if p is an int *, then p++ will move it by size of(int) bytes.
  • 14.
    Page 08 Example: Pointers andArrays: •The name of an array is actually a pointer to its first element. •You can manipulate arrays using pointers.
  • 15.
    About us studio shodweHome Startegy Contact Page 06
  • 16.
    Pointers and Functions •Callby Value: •Definition: In call by value, a copy of the variable is passed to the function. Changes made inside the function do not affect the original variable. •Example:
  • 17.
    About us studio shodweHome Startegy Contact Page 06
  • 18.
    Call by Reference: •Definition:In call by reference, a pointer to the variable is passed to the function. This means changes inside the function affect the original variable. •Example: Why Use Call by Reference: •It allows you to modify the actual value of the arguments passed. •It is useful when you need to return multiple values or work with large data structures efficiently.
  • 19.
    Key Differences BetweenCall by Value and Call by Reference
  • 20.
    About us studio shodweHome Startegy Contact Page 06
  • 21.
  • 22.
    About us studio shodweHome Startegy Page 03 What is an Array? Definition: An array is a collection of variables of the same data type that are stored in contiguous memory locations. Arrays are used to store multiple values under a single name, and you can access each element of the array using an index. •Key Points: •Arrays are indexed starting from 0. •All elements in an array must be of the same data type (e.g., all ints, all chars, etc.). •The size of an array is fixed once it is declared.
  • 23.
    Array Declaration •Syntax forDeclaring an Array: •type: The data type of the array elements (e.g., int, float, char). •array_name: The name of the array variable. •size: The number of elements in the array (must be a constant value).
  • 24.
    Example of ArrayDeclaration Explanation: •arr[5]: This declares an array of 5 integers. •name[20]: This declares an array to store 20 characters (often used for strings in C). •scores[10]: This declares an array of 10 floats.
  • 25.
    Accessing Array Elements •AccessingIndividual Elements: Array elements are accessed using indices (starting from 0):
  • 26.
    About us studio shodweHome Startegy Contact Page 06
  • 27.
    Array Initialization •Definition: Initialization isthe process of assigning values to the elements of the array at the time of declaration. •Syntax for Initialization:
  • 29.
    Partial Initialization: •If notall elements are initialized, the uninitialized elements will automatically be set to 0. String Initialization: A string in C is an array of characters, and it is typically initialized with the string literal. int arr[5] = {10, 20}; // Only the first two elements are initialized; rest will be 0 // arr = {10, 20, 0, 0, 0}
  • 30.
    Default Initialization Values •DefaultValues: •For integer arrays: uninitialized elements default to 0. •For character arrays: uninitialized elements default to '0' (null character). •For float/double arrays: uninitialized elements default to 0.0. Array Initialization Example •Example 1: Integer Array Initialization:
  • 31.
    Example 2: StringInitialization: Example 3: Float Array Initialization: C float scores[3] = {95.5, 87.2}; // Third element is automatically initialized to 0.0 // scores = {95.5, 87.2, 0.0}
  • 32.
    About us studio shodweHome Startegy Contact Page 06
  • 33.
    Multi-Dimensional Arrays •Definition: A multi-dimensionalarray is an array of arrays. It can be thought of as a table with rows and columns. This creates a 2x3 matrix, where matrix[0][0] = 1, matrix[0][1] = 2, etc.
  • 34.
  • 35.
    About us studio shodweHome Startegy Contact Page 06
  • 36.
    About us studio shodweHome Startegy Contact Page 06
  • 37.
    Page 02 As agroup, implement a simple C program utilizing pointers, arrays, and strings using the C Coding APP or any other platform. The group's program must be debugged, and another group will be responsible for troubleshooting it. Provide the answer key if necessary. The program must be fixed before the end of the class. Follow the troubleshooting format for the debugged program, ensuring that fixes are made for the specific line indicated by the group. Provide 10 errors for it. GROUP TASK: GROUP CODEFIX
  • 38.
    Page 02 In YellowPad paper follow this format: Answer format: ERROR- LINE-: FIX :
  • 39.
    Page 02 In YellowPad paper follow this format: Answer format: ERROR- LINE-: FIX :
  • 40.
    Rubrics CRITERIA DESCRIPTION SCORE ProgramStructure & Syntax (10 Points) The program follows correct syntax for pointers, arrays, and strings. Debugging Skills (10 Points) The group demonstrates effective debugging techniques. Identifies and fixes all errors in the program Peer Troubleshooting (10 Points) Groups demonstrate clear communication when explaining the debugging process. Teamwork (10 Points) The group actively collaborates, helping others troubleshoot the program Answer Key / Documentation (10 Points) The answer key includes proper explanations for any changes made to the original program. TOTAL 50
  • 41.
  • 42.
    What is <string.h>? Definition: The<string.h> header file in C provides functions for manipulating C-style strings (arrays of characters). Common Operations: •Comparing strings •Concatenating strings •Copying strings •Measuring string lengths •Searching for characters in strings
  • 43.
    Syntax: String Manipulation: The functionsin <string.h> are essential for working with null-terminated character arrays (C-strings).
  • 44.
    strcmp Function -Comparing Strings
  • 45.
    NOTE: Lexicographic order isa method of ordering elements in programming languages based on their alphabetical or numerical order.
  • 46.
    strcmp Function -Comparing Strings
  • 47.
    strcmp Function -Comparing Strings
  • 48.
    strcmp Function-Concatenating string Concatenationis the process of combining or joining two or more strings, text fragments, or variables together into a single string.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
    strrchr Function -Finding Last Occurrence of a Character
  • 58.
    strrchr Function -Finding Last Occurrence of a Character
  • 59.
  • 60.
  • 61.
    Page 02 As agroup, design a simple C program utilizing pointers, arrays, and strings using the C Coding APP or any other platform. The group's program must be debugged, and another group from the other section will be responsible for troubleshooting it. Provide the answer key if necessary. The program must be fixed before the end of the class. Follow the troubleshooting format for the debugged program, ensuring that fixes are made for the specific line indicated by the group. Provide 20 errors for it. PROGRAMMING TASK: C Program Fix-Up Challenge
  • 62.
    Page 02 In YellowPad paper follow this format: Answer format: ERROR- LINE-: FIX :