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,939 questions

51,876 answers

573 users

How to run for loop with function calls in C

2 Answers

0 votes
int f() {
    
    static int n = 7;
    
	return n--;
}
 
int main(int argc, char **argv) 
{
	for (f(); f(); f()) {
         printf("%d\n", f());
    }
	
	return 0; 
}
    
      
/*
run:
    
5
2
 
*/

 



answered Feb 27, 2019 by avibootz
0 votes
#include <stdio.h>
 
int f(char ch) {
    
    static int n = 7;
    
	// simulation - see how it work
	printf("ch = %c n = %d\n", ch, n);
	
	return n--;
}
 
int main(int argc, char **argv) 
{
	for (f('a'); f('b'); f('c')) {
         printf("%d\n", f('d'));
    }
	
	return 0; 
}
    
      
/*
run:
    
ch = a n = 7
ch = b n = 6
ch = d n = 5
5
ch = c n = 4
ch = b n = 3
ch = d n = 2
2
ch = c n = 1
ch = b n = 0
 
*/

 



answered Feb 28, 2019 by avibootz
edited Mar 2, 2019 by avibootz

Related questions

1 answer 618 views
618 views asked Nov 30, 2019 by avibootz
2 answers 292 views
1 answer 85 views
1 answer 78 views
78 views asked Dec 11, 2024 by avibootz
1 answer 105 views
1 answer 97 views
1 answer 105 views
...