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

Chapter 7 Notes

The document provides an overview of arrays in programming, highlighting their definition as collections of similar data types stored in contiguous memory locations. It includes syntax examples for declaring and initializing arrays, as well as input/output operations using scanf and printf. Additionally, it covers pointer arithmetic, the relationship between arrays and pointers, and the use of arrays as function arguments, along with a brief mention of multidimensional arrays.

Uploaded by

aalokpardeshi22
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)
2 views11 pages

Chapter 7 Notes

The document provides an overview of arrays in programming, highlighting their definition as collections of similar data types stored in contiguous memory locations. It includes syntax examples for declaring and initializing arrays, as well as input/output operations using scanf and printf. Additionally, it covers pointer arithmetic, the relationship between arrays and pointers, and the use of arrays as function arguments, along with a brief mention of multidimensional arrays.

Uploaded by

aalokpardeshi22
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