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 array parameter with static in function using C

1 Answer

0 votes
#include <stdio.h>
 
void f(double a[static 10], double b[static 10]) {
    for (int i = 0; i < 10; i++) {
        a[i] = i * 2;
        b[i] = a[i] + 1;
    }
}
 
int main(void)
{
    double a[10] = {0}, b[20] = {0};
    f(a, b); 
     
    double c[5] = {0};
    // f(b, c); // undefined behavior: array argument is too small
     
    for (int i = 0; i < 10; i++) {
        printf("%lf %lf\n", a[i], b[i]);
    }
}
   
   
   
/*
run:
   
0.000000 1.000000
2.000000 3.000000
4.000000 5.000000
6.000000 7.000000
8.000000 9.000000
10.000000 11.000000
12.000000 13.000000
14.000000 15.000000
16.000000 17.000000
18.000000 19.000000
   
*/

 



answered Mar 9, 2024 by avibootz
edited Mar 9, 2024 by avibootz

Related questions

1 answer 154 views
1 answer 137 views
1 answer 225 views
2 answers 243 views
1 answer 171 views
171 views asked Feb 1, 2020 by avibootz
1 answer 198 views
...