C/C++函数参数,传值域传址!!!
/*
* File: main.cpp
* Author: Vicky
*
* Created on 2010年5月8日, 下午2:47
*/
#include <iostream>
using namespace std;
void swap(int x, int y) {
cout << "x and y swap before : " << x << "\t" << y << endl;
int i = x;
x = y;
y = i;
cout << "x and y swap after : " << x << "\t" << y << endl;
}
void swap2(int * x, int * y) {
cout << "x and y swap before : " << *x << "\t" << *y << endl;
int * i = x;
x = y;
y = i;
cout << "x and y swap after : " << *x << "\t" << *y << endl;
}
/**
* 注意,此处非&x与&y并非地址,而是对象的别名!!!
*/
void swap3(int &x, int &y) {
cout << "x and y swap before : " << x << "\t" << y << endl;
int i = x;
x = y;
y = i;
cout << "x and y swap after : " << x << "\t" << y << endl;
}
/**
* 按址传递,传递的参数是地址.
*/
void swap4(int * x, int * y) {
cout << "x and y swap before : " << *x << "\t" << *y << endl;
int i = *x;
*x = *y;
*y = i;
cout << "x and y swap after : " << *x << "\t" << *y << endl;
}
int main(int argc, char** argv) {
int x = 1;
int y = 9;
cout << "main function swap before : " << x << "\t" << y << endl;
swap(x, y);
cout << "main function swap after : " << x << "\t" << y << endl;
// 可将,主函数的x与y并没有交换,表示swap函数交换的仅仅是x与y的副本
cout << "---------" << endl;
int * px = new int(1);
int * py = new int(9);
cout << "main function swap before : " << *px << "\t" << *py << endl;
swap2(px, py);
cout << "main function swap after : " << *px << "\t" << *py << en
相关文档:
解决步骤:
gylu@dell-desktop:~$ sudo apt-get install ckermit
显示安装过程
gylu@dell-desktop:~$gedit ~/.kermrc
输入下面内容后保存.kermrc退出:
set line /dev/ttyS0
set speed & ......
access(判断是否具有存取文件的权限)
相关函数 stat,open,chmod,chown,setuid,setgid
表头文件 #include<unistd.h>
定义函数 int access(const char * pathname,int mode);
函数说明 access()会检查是否可以读/写某一已存在的文件。参数mode有几种情况组合,R_OK ......
最近需要写一段程序,完成以下的工作,用java将数据以二进制的形式写入文件中,然后用C读出此二进制文件。
开始的时候没有考虑机器的字节序,直接搞出segment fault.想了很久,才明白原来是java和C的字节序是不一样的。
java中的字节序是big endian的,它是与机器无关的。而c的字机序是机器相关的,而当前用的机器是x84 ......
CAPTION: 关于C/C++中内存空间的划分
AUTHOR: aIsland 摘自中国IT实验室
DATE: 2010-05-30
E-MAIL: aIsland@live.cn
QQ: 418662213
P.S.
1.Bolanlan|随心high|aIsland 三个网名均为本人
2.声明aIsland 所收录的所有文章其著作权都属于原创作者
  ......