0% found this document useful (0 votes)
31 views16 pages

Unit 3 Array and Pointer

The document provides an overview of arrays and pointers in C programming, detailing their types, operations, and relationships. It explains how arrays are collections of similar data types and how pointers store memory addresses, including their use in accessing and manipulating arrays. Additionally, it covers the concept of arrays of pointers, their syntax, and comparisons with 2D arrays.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views16 pages

Unit 3 Array and Pointer

The document provides an overview of arrays and pointers in C programming, detailing their types, operations, and relationships. It explains how arrays are collections of similar data types and how pointers store memory addresses, including their use in accessing and manipulating arrays. Additionally, it covers the concept of arrays of pointers, their syntax, and comparisons with 2D arrays.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Course Title: Programming in C

Title of Topic: Arrays and Pointers


Introduction to Arrays
• Arrays are collections of similar data types stored in
contiguous memory.
• They simplify storage and retrieval using indexing.
• Example: int arr[5];
Types of Arrays
• 1D Arrays – List-like storage.
• 2D Arrays – Matrix form.
• Multidimensional Arrays – Advanced nested structures.
Array Operations
• Declare, initialize, access, and loop through arrays.
• C arrays are fixed size and lack boundary checks.
Introduction to Pointers
• Pointers store memory addresses.
• Use & to get address, * to get value at address.
• Example: int *p = &a;
Pointer Operators
• Address-of: &
• Dereference: *
• Pointer arithmetic: p++, p--, p+i
Relationship Between Arrays and
Pointers
• Array names are pointers to their first element.
• arr[i] is same as *(arr + i).
Accessing Arrays Using
Pointers
• Traverse arrays using pointer arithmetic.
• Example: *(arr + i) == arr[i]
Pointer to Arrays
• Pointers can point to entire arrays.
• Useful in function arguments for 2D arrays.
• Example: int (*p)[5];
Array of Pointers
• An array of pointers is a collection where each element stores
an address. Commonly used for strings, dynamic arrays, and
managing memory efficiently.
Syntax and Declaration
• data_type *array_name[size];
• Example:
• int *arr[5]; // array of 5 integer pointers
Array of Pointers to Strings
• char *names[] = {"Alice", "Bob", "Charlie"};
• Efficient for storing strings of variable lengths.
Accessing Elements
• names[0] → "Alice"
• names[1][0] → 'B'
• Use indexing like normal arrays but access through memory
addresses.
Array of Pointers vs 2D Array
• Array of Pointers: Dynamic, flexible, efficient for strings.
• 2D Array: Fixed size, uniform structure, ideal for matrix-like
data.
Example – Integers
• int a = 10, b = 20, c = 30;
• int *ptr[3] = {&a, &b, &c};
• Access using *ptr[i]
Looping Through Pointer
Array
• for (int i = 0; i < 3; i++) {
• printf("%d\n", *ptr[i]);
• }

You might also like