Code::Blocks Forums

User forums => Help => Topic started by: calinraducalin on December 04, 2011, 01:25:57 pm

Title: compilation error
Post by: calinraducalin on December 04, 2011, 01:25:57 pm
I am running Code::Blocks 10.05 on Mac OS X 10.6.8


void swap(int& a, int& b)
{
int aux;
printf("\nValues at entry: a=%d b=%d\n", a, b); aux=a; a=b; b=aux;
printf("\nValues at exit: a=%d b=%d\n", a, b);
}
void main()
{
int a, b;
a=2; b=3;
printf("\nIn the main function, prior to invoking swap: a=%d b=%d\n", a, b);
swap(a, b);
printf("\nIn the main function, after the return from swap: a=%d b=%d\n", a, b);
}

in compilation, it appears the following error:
error expected : "," , "," or ")" before token "&"

I have coppied the source from a book.
Title: Re: compilation error
Post by: zabzonk on December 04, 2011, 01:49:49 pm
You are trying to compile C++ as C code, probably because you have given the file a .c extension rather than a .cpp one. This is really not a Code::Blocks issue, and you should ask this and similar questions regarding C++ at sites like  http://www.reddit.com/r/learnprogramming
Title: Re: compilation error
Post by: calinraducalin on December 04, 2011, 01:58:04 pm
Thanks! your suggestion worked for me!