Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

10/10/23, 12:15 PM Access Array Using Pointer in C Language | PrepInsta

Prepare  Prime Video OffCampus Updates Placement Stats Login Get Prime

Access Array Using Pointer in C


Access Array Using Pointer:
On this page we will discuss about access array using pointer in C language and write a program for it.This will help to understand the basic
structure of arrays and pointers.We can understand pointer as an variable which holds the address of another variable.

Access Array Using Pointer in C Language


Related Pages
Array is collection of data items of homogeneous types at contiguous memory location.
Pointer is itself a variable which holds the address of another variable.
Function Pointer
Array can be initialized at declaration where as pointer can’t be initialized at declaration.We can access
the array elements using pointer.
Pointer v/s Array
Pointer to array means the pinter variable will hold the address to the first element of array of base
element of array let’s say p[0] where a is an array. Pointer in C
If we use * before pointer variable it will return the value store at the address.
Null Pointer

Example: Pointer to Pointer in C

int p[5] = {8, 9, 10, 11, 12};


int *ptr = p

Program 1:
Prime Course Trailer

#include <stdio.h> Run

int main ()
{
int p[5] = { 8, 9, 10, 11, 12 }, i;
int *ptr = p;

for (i = 0; i < 5; i++)


printf ("&p[%d] = %p \t p[%d] = %d\n", i, ptr + i, i, *(ptr + i));

return 0;
} Related Banners

Output:

https://prepinsta.com/all-about-c-language/access-array-using-pointer/ 1/3
10/10/23, 12:15 PM Access Array Using Pointer in C Language | PrepInsta

&p[0] = 0x7ffeafbc9190 p[0] = 8


&p[1] = 0x7ffeafbc9194 p[1] = 9
&p[2] = 0x7ffeafbc9198 p[2] = 10
&p[3] = 0x7ffeafbc919c p[3] = 11
&p[4] = 0x7ffeafbc91a0 p[4] = 12

Program 2:Modifying Elements of Array Using


Pointer Get PrepInsta Prime & get Access to all
200+ courses offered by PrepInsta in

Run
One Subscription
#include<stdio.h>

int main ()
{ Get Prime
int p[5] = { 8, 9, 10, 11, 12 }, i;
int *ptr = p;
*(ptr+3) = 16;

for (i = 0; i < 5; i++)


printf ("&p[%d] = %p \t p[%d] = %d\n", i, ptr + i, i, *(ptr + i));

return 0;
}
//4th element is modified from 11 to 16

Output:
&p[0] = 0x7ffef151f3c0 p[0] = 8
&p[1] = 0x7ffef151f3c4 p[1] = 9
&p[2] = 0x7ffef151f3c8 p[2] = 10
&p[3] = 0x7ffef151f3cc p[3] = 16
&p[4] = 0x7ffef151f3d0 p[4] = 12

Get over 200+


course One
Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java,
Python, DSA (All Languages), Competitive Coding (All Languages), TCS,
Infosys, Wipro, Amazon, DBMS, SQL and others

Get Prime Course List

Checkout list of all the video courses in PrepInsta Prime Checkout


Subscription

Login/Signup to comment

Support Companies All Exams Dashboards Get In Touch Get In Touch


Contact Us Accenture Microsoft CoCubes Dashboard Instagram support@prepinsta.com
About Us Cognizant TCS eLitmus Dashboard Linkedin +91-8448440710

PrepInsta.com Refund Policy MindTree Infosys HirePro Dashboard Youtube Text us on


Privacy Policy VMware Oracle MeritTrac Dashboard Telegram Whatsapp/Instagram
No.1 and most visited website for Placements in India. Services CapGemini HCL Mettl Dashboard Facebook

Disclaimer Deloitte TCS Ninja DevSquare Dashboard Twitter


We help students to prepare for placements with the
Terms and Conditions Wipro IBM
best study material, online classes, Sectional Statistics for
better focus and Success stories & tips by Toppers on
PrepInsta.

https://prepinsta.com/all-about-c-language/access-array-using-pointer/ 2/3
10/10/23, 12:15 PM Access Array Using Pointer in C Language | PrepInsta
© 2023 Prep Insta

Privacy Policy | Copyright © 2023 Prep Insta

https://prepinsta.com/all-about-c-language/access-array-using-pointer/ 3/3

You might also like