CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C++ 语言

几个简单问题请教大家!

楼主jsrgmt(把根留住)2004-11-02 21:26:53 在 C/C++ / C++ 语言 提问

1、C/C++中自动(auto)变量,static变量,全局变量有什么不同?  
  2、C/C++中字符串数组和字符串指针在编程上有何异同?  
  3、结合某个操作系统说说中断服务例程运行在哪个线程或进程的上下文中?  
  4、什么是调用序列?C语言中有几种调用序列?用调用序列说明如何实现printf这样的可变数目参数的函数,其原理是什么?  
  5、有如下关系Scores(StuNo#,Class,Score),请用一条SQL语句列出所有及格学生(>=60)的平均成绩>=80的班级及其及格学生的平均成绩,并按成绩排序! 问题点数:50、回复次数:7Top

1 楼xMars(火星虫:最简单的人工智能)回复于 2004-11-02 21:31:59 得分 10

1.  
  The   auto   Keyword  
  Few   programmers   use   the   auto   keyword   in   declarations   because   all   block-scoped   objects   not   explicitly   declared   with   another   storage   class   are   implicitly   automatic.   Therefore,   the   following   two   declarations   are   equivalent:  
   
  {  
  auto   int   i;         //   Explicitly   declared   as   auto.  
  int             j;         //   Implicitly   auto.  
  }  
   
   
   
  static  
  static   declarator  
   
  When   modifying   a   variable,   the   static   keyword   specifies   that   the   variable   has   static   duration   (it   is   allocated   when   the   program   begins   and   deallocated   when   the   program   ends)   and   initializes   it   to   0   unless   another   value   is   specified.   When   modifying   a   variable   or   function   at   file   scope,   the   static   keyword   specifies   that   the   variable   or   function   has   internal   linkage   (its   name   is   not   visible   from   outside   the   file   in   which   it   is   declared).    
   
  In   C++,   when   modifying   a   data   member   in   a   class   declaration,   the   static   keyword   specifies   that   one   copy   of   the   member   is   shared   by   all   the   instances   of   the   class.   When   modifying   a   member   function   in   a   class   declaration,   the   static   keyword   specifies   that   the   function   accesses   only   static   members.  
   
  For   related   information,   see   auto,   extern,   and   register.  
   
  Example  
   
  //   Example   of   the   static   keyword  
  static   int   i;                   //   Variable   accessible   only   from   this   file  
   
  static   void   func();       //   Function   accessible   only   from   this   file  
   
  int   max_so_far(   int   curr   )  
  {  
        static   int   biggest;         //   Variable   whose   value   is   retained  
                                                      //         between   each   function   call  
        if(   curr   >   biggest   )  
              biggest   =   curr;  
   
        return   biggest;  
  }  
   
  //   C++   only  
   
  class   SavingsAccount  
  {  
  public:  
        static   void   setInterest(   float   newValue   )     //   Member   function  
              {   currentRate   =   newValue;   }                           //         that   accesses  
                                                                                              //         only   static  
                                                                                              //         members  
  private:  
        char   name[30];  
        float   total;  
        static   float   currentRate;         //   One   copy   of   this   member   is  
                                                                  //         shared   among   all   instances  
                                                                  //         of   SavingsAccount  
  };  
   
  //   Static   data   members   must   be   initialized   at   file   scope,   even  
  //         if   private.  
  float   SavingsAccount::currentRate   =   0.00154;  
   
   
   
  Top

2 楼zhangfjj(小张)回复于 2004-11-02 21:33:57 得分 15

1、C/C++中自动(auto)变量,static变量,全局变量有什么不同?  
          作用域与生存期不同  
   
  2、C/C++中字符串数组和字符串指针在编程上有何异同?  
          字符串数组?那是指针数组,我想你说的是字符数组吧。  
          char   str[]="abcd";//分配5个字节的内存"abcd"串  
          char   *p="abcd";//分配4(32位编译器)个字节给指针变量,并使它指向字符串,而字符串分配在常量区,也要占5个字节Top

3 楼lynnboy(lynnboy)回复于 2004-11-02 22:10:02 得分 25

这叫简单问题?哈!  
   
  3、结合某个操作系统说说中断服务例程运行在哪个线程或进程的上下文中?  
  中断服务是在系统进程的上下文里的。  
  比如Windows操作系统,为整个系统分了   32   个   IRQL(中断请求排队优先级),所有用户线程在最低优先级执行PASSIVE_IRQL,线程调度和延迟过程调用在倒数第二个优先级DESPATCI_IRQL,而从此往上,是所有可能的中断的处理例程执行的优先级。此时CPU工作在内核模式,绝对没有用户线程上下文。  
   
  4、什么是调用序列?C语言中有几种调用序列?用调用序列说明如何实现printf这样的可变数目参数的函数,其原理是什么?  
  调用序列就是关于调用者和被调用函数之间怎样传递参数,返回值,清理运行栈空间的约定协议。以Microsoft   C/C++   compiler   为例,其有如下几种调用约定:  
  __cdecl,由右向左将参数入栈,由调用者负责恢复栈顶指针,是C的传统调用约定。  
  __stdcall,由右向左将参数入栈,由被调用函数返回前恢复栈顶指针,可以节省代码空间。  
  __fastcall,由右向左将参数入栈,前面两个参数由寄存器ECX和EDX传递,可以加快调用速度。由被调用函数返回前恢复栈顶指针  
  thiscall,C++特有的调用类成员函数的调用约定,由右向左将参数入栈,将this指针存放在ECX中。由被调用函数返回前恢复栈顶指针  
  只有__cdecl可以实现变参数函数,因为只有调用者知道实际上传递了多少个参数,所以必须由调用者来恢复栈顶指针。  
   
  Top

4 楼goodluckyxl(被人遗忘的狗)回复于 2004-11-03 08:37:34 得分 0

大家这么尽力写这么多    
   
  我只好除了学习   还能怎样   0^_^0Top

5 楼xuzheng318(忧郁王子)回复于 2004-11-03 08:45:14 得分 0

一起学习   ^_^!Top

6 楼kobefly(科比--网络学习中)回复于 2004-11-03 08:57:23 得分 0

又学到了东西,很不错的说  
  我怎么现在对C语言的回调机制还不明白呢?  
  郁闷  
  学C,这个CALLBACK都不明白怎么办呢?  
  Top

7 楼zjraycj(无名)回复于 2004-11-03 09:07:28 得分 0

好问题啊Top

相关问题

  • 几个简单的问题
  • 几个简单问题。
  • 几个简单的问题
  • 问几个简单问题
  • 几个简单的问题。
  • 几个简单的问题。。。
  • 几个简单的问题?
  • 几个简单的问题。。。
  • 几个简单的问题
  • 几个简单问题

关键词

  • c++
  • 指针
  • 函数
  • 中断
  • 线程
  • 调用
  • 字符串
  • 参数
  • 变量
  • 序列

得分解答快速导航

  • 帖主:jsrgmt
  • xMars
  • zhangfjj
  • lynnboy

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo