c - pointer is also pass by value
when pointer as param of function, it is also pass by value:
* you can change the value that the pointer point to by the address(the value of pointer),
* but you can't change the original value of pointer in the function,
* if you want to change the pointer, you need to return the new address from function, and assign it to the pointer outside the function,
e.g.
pass_by_value.c:
#include <stdio.h>
#include <string.h>
char *test(char *s) {
s = strdup("s2");
return s;
}
main() {
char *s1;
s1 = "s1";
printf("%s\n", s1); // s1
test(s1);
printf("%s\n", s1); // s1, because pointer param of function is also pass by value, you can't change the original value of pointer in the function, even though you can change the value it point to by the address(the value of pointer).
s1 = test(s1);
printf("%s\n", s1); // s2, because new address is returned from function, and assign to pointer outside the function.
}
分享到:
相关推荐
红烛电子教鞭E-Pointer能在电脑屏幕上任何写画,用于教学演示,产品展示。其体积小功能多,是教师教学的得力助手。在屏幕上的操作可保存为JPG或BMP格式图片,软件启动后,按下热键F9即可显示操作界面。使用说明:1....
红烛教鞭
仿qt的d-pointer技术的另一种实现
e-Pointer 是一个绿色小巧的电子教鞭工具,你可以把你的电脑屏幕当成黑板(白板也行), 在上面任意涂抹,画画,写字,这对于电脑教学可是很有意义的. 1.0经典版本,后来的都不好用!
代码指针完整性,Volodymyr Kuznetsov∗, La ́szlo ́ Szekeres‡, Mathias Payer†,§ George Candea∗, R. Sekar‡, Dawn Song†
e-Pointer.你可以把你的电脑屏幕当成黑板(白板也行),在上面任意涂抹,画画,写字,是教师教学的得力助手,写画计算机屏幕。用于教学演示,产品展示主要特征: 纯汇编编译!性能卓越体积极小。画屏:可以画直线、虚线、...
电子粉笔,小巧实用,电脑演示辅助软件e-pointer1[1].0.rar
特别适合计算机老师讲课时使用,可以在桌面上随便标识,操作,简单实用。
这个工具用于在电子上课或在线上课的时候使用。
桌面冻结涂鸦,可以画线、画圈,写字。快捷键F9。安全无广告,亲测可用。。。。。。。。。。。。。。。。。。
红烛教鞭 (e-Pointer)V2.2 绿色特别版;红烛教鞭 (e-Pointer)V2.2 绿色特别版.rar.
当在看幻灯片等的时候,如果有一个功能可以的教鞭式会让学习与教学更加得心应手
dangling-pointer-rampage-master.rar
一个可以在桌面画画,写字的小软件,很实用
如果你用的是W9.0以下的版本或Tajima(各版本),在关闭打版软件后出现了上面的消息框,如果你的软件在操作系统升级前没有这个现象的话,可以肯定你在用XP-SP2,这是因为XP-SP2增强了内存管理和安全...BAD-POINTER 报错
Code-Pointer_Integrity.pdf
桌面涂抹软件E-pointer_2.5.1.0
如果你用的是W9.0以下的版本或Tajima(各版本),在关闭打版软件后出现了上面的消息框,如果你的软件在操作系统升级前没有这个现象的话,可以肯定你在用XP-SP2,这是因为XP-SP2增强了内存管理和安全...BAD-POINTER 报错
详解函数指针和指针函数的区别和使用,对深刻理解二者非常有用.
讲述了C程序中指针的使用的常见的错误类型.可以帮助学者更好的使用和了解指针.About the use of pointers in C program the common error types can be used and to help scholars better understand the pointer.