I want to make a function to pass and return values from the same arguments. For example prm3=0 after function's execution must become prm3=3, and next prm3=6, and next prm3=9 ...

I wrote the following but it doesn't work. p1,p2,p3 are not passed to prm1, prm2, prm3. What is wrong? Any example returning more than one values?

#include <stdio.h>

void increments (int prm1, int prm2, int prm3);
int	prm1=0, prm2=0, prm3=0;

int main(void)
{
	while (1){
		increments (prm1, prm2, prm3);
	}
	return (0);
}

void increments (int p1, int p2, int p3){
	p1 += 1;
	p2 += 2;
	p3 += 3;
}

Recommended Answers

All 2 Replies

I want to make a function to pass and return values from the same arguments. For example prm3=0 after function's execution must become prm3=3, and next prm3=6, and next prm3=9 ...

You are passing parameters by value. Pass pointers instead.

#include <stdio.h>

void increments (int* p1, int* p2, int* p3);
int prm1 = 0, prm2 = 0, prm3 = 0;

int main(void) {
  increments (&prm1, &prm2, &prm3);
  return (0);
}

void increments (int* p1, int* p2, int* p3){
	*p1 += 1;
	*p2 += 2;
	*p3 += 3;
}

Also it is strongly recommended for you to read K&R or any other referencial manual about C language.

ok, thanx for your response, I will follow your suggestions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.