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.

39,851 questions

51,772 answers

573 users

How to pass an array of pointers to a function in C

2 Answers

0 votes
#include <stdio.h>
 
void print_array(char* arr[], int size) {
    for (int i = 0; i < size; i++) {
        puts(arr[i]);
    }
}
 
int main(void) {
    char* arr[] = { "c", "java", "php", "c++" };
 
    print_array(arr, sizeof(arr) / sizeof(arr[0]));
 
    return 0;
}
 
 
 
 
/*
run:
 
c
java
php
c++
 
*/

 



answered May 6, 2023 by avibootz
edited Jun 20, 2024 by avibootz
0 votes
#include <stdio.h>
   
void print_array(int** arraypp, int size) {
    for (int i = 0; i < size; i++) {
        printf("%d ", *arraypp[i]);
    }
    
    printf("\n");
}
 
int main() {
    int array[] = {8, 3, 17, 6, 90};
    int* arrayp[] = {&array[0], &array[1], &array[2], &array[3], &array[4]};

    print_array(arrayp, sizeof(arrayp) / sizeof(arrayp[0]));

    return 0;
}


        
/*
run:
      
8 3 17 6 90
         
*/

 



answered Jun 20, 2024 by avibootz

Related questions

3 answers 1,569 views
1 answer 179 views
1 answer 119 views
1 answer 145 views
1 answer 139 views
1 answer 46 views
...