#include "stdafx.h"
#include "string.h"
struct student
{
 int num;
 ];
 char sex;
};
struct student *fun(struct student stu)
{
 struct student *p;
 stu.num = ;
 strcpy_s(stu.name, "abc");
 stu.sex = 'G';
 p = &stu;
 return p;
}
int main()
{
 struct student stu1,*pp;
 stu1.num = ;
 strcpy_s(stu1.name, "def");
 stu1.sex = 'M';
 printf("num=%d name=%s sex=%c\n",stu1.num,stu1.name,stu1.sex);
 pp = fun(stu1);
 printf("num=%d name=%s sex=%c\n", (*pp).num, (*pp).name, (*pp).sex);//name输出乱码,求解释
 ;
}
进入fun函数时,会创建一个局部变量形参stu,这个形参stu与实参stu1不是一回事,stu只是与stu1 数据一模一样的复制品而已。当fun函数对stu操作结束后返回stu的指针,但因为stu是局部变量,在fun函数结束后会释放掉,由于main函数使 用fun函数返回的指针pp,pp指向了已被释放掉的stu,所以打印时必然输出些乱码。改为static变量

static用法一的更多相关文章

  1. aspx 页面中 js 引用与页面后台的数据交互 --【 js 调后台】

    后台调用 js 方法 前台调用后台方法与变量:  后台被调用的方法必须是public 或 protected 后台被调用的方法必须是静态的static 方法一:通过WebService来实现 步骤: ...

  2. Linux学习系列之Nginx调优实战

    Nginx配置文件性能微调 全局的配置 user www-data; pid /var/run/nginx.pid; worker_processes auto; worker_rlimit_nofi ...

  3. Nginx调优实战

    Nginx配置文件性能微调 全局的配置 user www-data; pid /var/run/nginx.pid; worker_processes auto; worker_rlimit_nofi ...

  4. Java SE 第二十三讲----static关键字and final关键字

    1.static关键字 [在二十二讲视频中30分钟开始讲授] 2.static修饰属性:无论一个类生成了多少个对象,所有这些对象共同使用唯一一份静态的成员变量:一个对象对该静态成员变量进行了修改,其他 ...

  5. *两个关键字static和final

    static关键字:可以用于修饰属性,也可以用于修饰方法,还可以用于修饰类. static 修饰属性: 无论一个类生成了多少个对象,所有这些对象共同使用唯一一份静态的成员变量:一个对象对该静态成员变量 ...

  6. 关于Java中static关键字的用法以及从内存角度解析

    在Java中,static可以用来修饰成员变量和成员方法. 修饰成员变量,称为静态成员方法 修饰静态方法,称为静态成员方法 搞清楚用法和区别之前,先搞清static声明的变量和普通非静态变量在内存的分 ...

  7. “Cannot make a static reference to the non-static method”处理方法

    报错原文:Cannot make a static reference to the non-static method maxArea(Shape[]) from the type ShapeTes ...

  8. java 中 Cannot make a static reference to the non-static 解决方法

    今天敲代码的时候遇到了这个问题,大体这个问题可以简化成这样: public class Test1 { public String get() { return "123"; } ...

  9. IOS-更优雅地使用Static Cell

    更优雅地使用Static Cell 在项目开发中,经常会用到static cell来实现一些固定的列表界面(如:个人中心等),在static cell被点击时,如何判断被点击的cell是哪一个,有什么 ...

随机推荐

  1. 适配iOS7uinavigationbar遮挡tableView的问题

    //适配iOS7uinavigationbar遮挡tableView的问题 if([[[UIDevice currentDevice]systemVersion]floatValue]>=7.0 ...

  2. ViewPager切换大量Fragment不刷新的问题

    PagerAdapter,需要重写instantiateItem()加载视图,onDestroy()销毁视图FragmentPagerAdapter,每一个生成的Fargment都保存在内存中,也就是 ...

  3. LeanCloud使用入门(android)

    LeanCloud算是一个简单易用的云服务器,其中包含了强大的数据库支持,我们只需要将此服务器应用到本地的代码即可实现后台的存储与交互. 那么,如何简单实现本地代码和LeanCloud服务器的交互呢? ...

  4. IOS 获取wifi的SSID

    #import <SystemConfiguration/CaptiveNetwork.h> - (NSString *)currentWifiSSID { // Does not wor ...

  5. POJ 2559 Largest Rectangle in a Histogram (单调栈或者dp)

    Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15831 ...

  6. SpringMVC10数据验证

    /** * @NotBlank 作用在String * @NotEmpty 作用在集合上 * @NotNull 作用在基本数据类型上 * */ public class User { @NotNull ...

  7. 转载:C#中&与&&的区别

    原文地址:http://www.cnblogs.com/chinafine/archive/2009/02/17/1392309.html   感谢博主分享! 二元运算符 (&) 为整型和 b ...

  8. Android中Action

    1 Intent.ACTION_MAIN String: android.intent.action.MAIN 标识Activity为一个程序的开始.比较常用. <activity androi ...

  9. 依赖注入与Unity(一) 介绍

        在你学习依赖注入和Unity之前,你需要明白你为什么要使用它们.为了明白为什么要使用它们,你应该明白依赖注入和Unity能够帮助你解决什么类型的问题.作为介绍部分,这一章不会涉及太多关于Uni ...

  10. CSS3 @font-face详细用法(转)

      @font-face是CSS3中的一个模块,他主要是把自己定义的Web字体嵌入到你的网页中,随着@font-face模块的出现,我们在Web的开发中使用字体就不用再为只能使用Web安全字体烦恼了! ...