UNIT–III ARRAYS & STRINGS
• Prepared for C Programming Class
• Faculty Presentation
Arrays – Definition
• • Finite ordered collection of homogenous
data
• • Stored in contiguous memory
• • Index starts at 0
Array Declaration
• Syntax: dataType arrayName[size]
• Example: float marks[5];
• Size and type cannot be changed after
declaration
Array Initialization
• 1. Compile-time: int a[5]={1,2,3,4,5}
• 2. Runtime using scanf()
• Uninitialized elements contain garbage values
Accessing & Updating Array
Elements
• arr[i] – access element
• arr[i] = value – update element
Memory Model
• Address = Base + (index * size)
• Example: a[4] = 2000 + 4*4 = 2016
Programs on Arrays: Reverse Array
• • Input n values
• • Print array elements in reverse order
Program: Sum of Array Elements
• • Traverse array and accumulate sum in a
variable
Program: Copy Array
• • Copy arr1 elements into arr2 element-by-
element
Program: Maximum and Minimum
• • Traverse array
• • Compare each element to find max/min
Program: Sort Ascending
• • Compare and swap elements
• • Nested loops
Two-Dimensional Arrays
• • Array of arrays
• • Syntax: int a[r][c]
• • Requires row & column index
2D Array Initialization
• 1. Single list
• 2. Row-wise nested list
Matrix Operations
• • Addition
• • Multiplication
• • Transpose
Introduction to Strings
• • Sequence of characters ending with 0
• • Strings are character arrays
String Declaration & Initialization
• char s[10];
• char s[]="hello";
• char s[]={'h','i','0'};
Reading Strings
• scanf() – stops at whitespace
• gets() – reads full string
• puts() – prints string
Traversing Strings
• • Using length
• • Using null character 0
String Handling Functions
• strlen(), strcat(), strcpy(), strcmp(), strrev()
Programs Without Built-in
Functions
• • Manual string length
• • String compare
• • String copy
• • String concatenation
• • String reverse
Character Frequency & Counting
• • Count vowels, consonants, digits, spaces
Sorting Strings Alphabetically
• • Compare using strcmp()
• • Swap strings if out of order
Case Conversion Program
• Convert string to UPPER/lower case
UNIT–III Programs Summary
• • Palindrome check
• • Mean of numbers
• • Search element
• • Sort names alphabetically

C_Programming_Arrays_Strings_Presentation.pptx