Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Pointers and 2-D Arrays | Two dimensional Array | Data Structures & Algorithm Tutorials

Rating
-
Sold
-
Pages
1
Uploaded on
06-11-2023
Written in
2019/2020

Improve your knowledge in arrays

Institution
Course

Content preview

1.4 Pointers and 2-D Arrays | Two dimensional Array | Data
Structures & Algorithm Tutorials
Jenny's Lectures CS IT
2D Arrays and Pointers
In this lesson, we will discuss how 2D arrays are related to
pointers and how you can access the elements of a 2D array
with the help of pointers. Let us take the example of a 3x3
matrix:

 659
 123
 487
This 2D array can be initialized at compile time and is an array
of arrays. Each 1D array has three integer elements and the 2D
array is an array of 3 1D arrays. The element at [0][0] is 6, and
the base address of the array is 100.

A pointer variable can be declared to contain the address of an
integer variable. However, the name of the 2D array cannot be
used as it returns a pointer to the first element, which is a 1D
array and not an integer variable. Instead, the address of [0][0]
can be used.

To print the address of the 2D array, you can use the format
specifier %p for hexadecimal or %u for unsigned integer. You
can also use the name of the array or the address of [0][0].
The value at the address can be printed using the
dereferencing operator (*).

When accessing a 1D array, the name of the array will return
the address of the first element, while adding 1 to the pointer
will point to the next element. Similarly, when accessing a 2D
array, the name of the array will return a pointer to the first
element, and adding 1 to the pointer will point to the next
element. To print the value at a specific index of the array, use
the dereferencing operator. You can also use a double pointer
to access values in a 2D array. To access a value at a specific
index, use the expression a[i][j] or s*(a+i)+j. You can also use
a pointer variable instead of the array name to access values.

Written for

Course

Document information

Uploaded on
November 6, 2023
Number of pages
1
Written in
2019/2020
Type
Class notes
Professor(s)
Jenny
Contains
All classes

Subjects

$7.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
SARAVANAVEL

Get to know the seller

Seller avatar
SARAVANAVEL Srinivasa subbaraya college
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
4
Last sold
-
Saravana's notes

Improve your knowledge in education by studies

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions