Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,026 questions

51,982 answers

573 users

How to use pointer to array of pointers in C

2 Answers

0 votes
#include <stdio.h>
  
#define LEN 5

int main ()
{
	int arr[] = {3, 5, 23, 871, 2};  
	int *array_of_pointers[LEN]; 
   
	for (int i = 0; i < LEN; i++) {
		array_of_pointers[i] = &arr[i];    
	}	
	
	int **pp  = array_of_pointers;
   
	for (int i = 0; i < LEN; i++) {
		printf("arr[%d] = %d\n", i, *pp[i]);
	}
   
	return 0;
}





/*
run:

arr[0] = 3
arr[1] = 5
arr[2] = 23
arr[3] = 871
arr[4] = 2

*/

 



answered Jan 29, 2020 by avibootz
0 votes
#include <stdio.h>
  
#define LEN 5

int main ()
{
	int arr[] = {3, 5, 23, 871, 2};  
	int *array_of_pointers[LEN]; 
   
	for (int i = 0; i < LEN; i++) {
		array_of_pointers[i] = &arr[i];    
	}	
	
	int* (*pp)[LEN] = &array_of_pointers;
   
	for (int i = 0; i < LEN; i++) {
		printf("arr[%d] = %d\n", i, *(*pp)[i]);
	}
   
	return 0;
}





/*
run:

arr[0] = 3
arr[1] = 5
arr[2] = 23
arr[3] = 871
arr[4] = 2

*/

 



answered Jan 29, 2020 by avibootz

Related questions

1 answer 189 views
1 answer 137 views
1 answer 89 views
89 views asked Mar 20, 2022 by avibootz
...