2012.9.20 IGT笔试简记


1.输出结果:

#include <iostream>

using namespace std;

class Person
{
      public:
              char Name[10];
              int Age;
};

int main()
{
    Person a; 
    cout<<sizeof(int)<<endl;
    cout<<sizeof(double)<<endl; 
    cout<<sizeof(a)<<endl;
    
    return 0; 
} 
答案:

4

8

16  


2.输出结果:

#include <iostream>

#define BAND(x) (((x)>=5&&(x)<=10)?x:0) 

using namespace std;


int main()
{
    int a=4; 
    cout<<"BAND(++a)="<<BAND(++a)<<endl; 
    
    return 0; 
} 
答案:

BAND(++a)=7

解析:将(++a)带入宏定义,有(((++a)>=5 && (++a)<=10)?(++a):0),可以看出对a进行了三次++操作。


3.singleton mode and its implementation

4.static in C++

5.pure virtual function

6. Reverse string: as "Hello world" into "world Hello"

#include <iostream>
#include <string>
#include <vector> 

using namespace std;

int main()
{
    vector<string> vstr; 
    string str;
    
    cout<<"Please input a string:"<<endl;
    while(cin>>str)
    vstr.push_back(str);
     
    vector<string>::reverse_iterator riter=vstr.rbegin();
    for(riter;riter!=vstr.rend();++riter)
        cout<<*riter<<" "; 
    cout<<endl;
     
    return 0; 
} 
输出结果:


解析:

用到了vector容器中的反向迭代器reverse_iterator(Iterator that addresses elements in reverse order),需要与此匹配的就是c.rbegin()c.rend()了,分别返回容器c中的最后下一个的元素和最开始的元素。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值