0% found this document useful (0 votes)
6 views11 pages

Chapter 7 Notes

The document provides an overview of arrays in programming, including their syntax, initialization, and memory allocation. It discusses pointer arithmetic, how arrays can be treated as pointers, and how to traverse arrays. Additionally, it covers the use of arrays as function arguments and introduces multidimensional arrays with examples.

Uploaded by

Sudha Tripathi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views11 pages

Chapter 7 Notes

The document provides an overview of arrays in programming, including their syntax, initialization, and memory allocation. It discusses pointer arithmetic, how arrays can be treated as pointers, and how to traverse arrays. Additionally, it covers the use of arrays as function arguments and introduces multidimensional arrays with examples.

Uploaded by

Sudha Tripathi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Arrays

Collection of similar data types stored at


contiguous memory locations
Syntax
int marks[3];

char name[10];
float price[2];
Input & Output
scanf("%d", &marks[0]);

printf("%d", marks[0]);
Inititalization of Array
int marks[ ] = {97, 98, 89};

int marks[ 3 ] = {97, 98, 89};

Memory Reserved :
Pointer Arithmetic
Pointer can be incremented
& decremented

CASE 1
Pointer Arithmetic
CASE 2

CASE 3
Pointer Arithmetic

- We can also subtract one pointer from another

- We can also compare 2 pointers


Array is a Pointer

int *ptr = &arr[0];

int *ptr = arr;


Traverse an Array
int aadhar[10];
int *ptr = &aadhar[0];
Arrays as Function Argument
//Function Declaration
void printNumbers (int arr[ ], int n)
OR
void printNumbers (int *arr, int n)

//Function Call
printNumbers(arr, n);
Multidimensional Arrays
2 D Arrays
int arr[ ][ ] = { {1, 2}, {3, 4} }; //Declare

//Access
arr[0][0]
arr[0][1]
arr[1][0]
arr[1][1]

You might also like