Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am having problem compiling this code for swapping two numbers using functions, here's my code:
#include<iostream.h>
#include<conio.h>
void swap(int,int)
void main()
{
clrscr();
int a,b;
cout<<"Enter two numbers a and b: ";
cin>>a>>b;
swap(a,b);
cout<<"After swapping a and b are "<<a<<" and "<<b;
getch();
}
void swap(int a, int b)
{
int t;
t=a;
a=b;
b=t;
}


I'm getting 'Declaration Syntax Error' at void main()
Can you tell me what is wrong? Thanks!
Posted
Updated 23-Jan-14 10:53am
v2
Comments
Aescleal 23-Jan-14 23:35pm    
If you're learning C++ (looking at your code and the way it won't work I assume you are) you might want to get yourself a compiler that's not some relic of the Dark Ages. Grab a copy of the latest version of g++ your OS can handle or Visual C++ if you use Windows.

1 solution

You are missing a semi-colon at the end of your swap function prototype.
 
Share this answer
 
Comments
Member 10545215 23-Jan-14 17:00pm    
Thank You!!
Sergey Alexandrovich Kryukov 24-Jan-14 1:50am    
Caught, 5ed...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900