我刚开始学习C++,并且遇到了这个函数声明的概念。它说“一个函数必须在使用之前声明”,但我已经写了一个程序,我已经评论了函数声明并使用了该函数。我的程序还在工作。 我想知道我在这里失踪。 我在eclipse上运行这个程序。 这是一个简单的程序,我将a和b的引用传递给交换函数和交换a和b的值。使用函数之前,即使没有函数声明,C++程序也在工作
#include <iostream>
#include <stdio.h>
#pragma pack(1)
using namespace std;
//void swap(int &,int &);
int main()
{
int num1,num2;
cout<<endl<<"Enter two nos\n";
cin>>num1>>num2;
cout<<"\nBefore call\t"<<num1<<"\t"<<num2<<endl;
swap(num1,num2);
cout<<"\nAfter call\t"<<num1<<"\t"<<num2<<endl;
}
void swap(int &a,int &b) //Saving memory here
{
int c=a;
a=b;
b=c;
}
'using namespace std ;' strike again。 –