Winter Bootcamp in ML and IoT in Jaipur
 Course content (For Bootcamp & Winter Training):- Machine Learning (ML) || Internet of Things (IoT) || Register for winter bootcamp
0 like 0 dislike
in Tutorial & Interview questions by (3.4k points)

Iterating through an array using pointers

1 Answer

0 like 0 dislike
by (3.4k points)
Best answer
#include <stdio.h>

#define SIZE (10)

int main()


size_t i = 0;    

int *p = NULL;    

int a[SIZE];       /* Setting up the values to be i*i */    

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


a[i] = i * i;    

}       /* Reading the values using pointers */    

for(p = a; p < a + SIZE; ++p)    


printf("%d\n", *p);    


return 0;


Here, in the initialization of p in the first for loop condition, the array a decays to a pointer to its first element, as it would in almost all places where such an array variable is used.

Then, the ++p performs pointer arithmetic on the pointer p and walks one by one through the elements of the

array, and refers to them by dereferencing them with *p.

Winter 10 Days boot-camp classes(7 HRS Daily) will start from 5, 20 & 27 December 2019 in:
1) Internet of things(IoT) Using RASPBERRY-PI
2) Machine Learning (ML)

70% OFF| Fee-INR 3,000/-

Limited seats!! Hurry up!!

[[ CALL - 07976731765 ]]

Some Study Resources are compiled from original Stack Overflow Documentation, the content is developed by the different experts at Stack Overflow. Study resources are released under Creative Commons BY-SA. Images may be copyright of their respective owners. This website is for self-learning and not affiliated with Stack Overflow. All trademarks and registered trademarks are the property of their respective company owners. Please send feedback and corrections to

Goeduhub Important Lists Our Youtube Channels (For free E-learning)
About Us List of IITs Goeduhub Technologies
Contact Us List of NITs AI and Big Data-HADOOP E-Learning Series
  List of PSUs Smart Learning PLC-SCADA, IoT and Raspberry-PI
  List of Exams After Graduation