C/C++专项练习 (三)

本文提供了几个C/C++编程题目,涉及内存对齐、数据类型、数组操作、全局变量引用、迭代器运算符重载等知识点,通过实例解析加深理解。
摘要由CSDN通过智能技术生成

1.在32位操作系统gcc编译器环境下,下面程序的运行结果为()

#include <iostream>
using namespace std;
class A {
public:
    int b;
    char c;
    virtual void print() {
        cout << "this is father’s fuction! " << endl;
    }
};
class B: A {
public:
    virtual void print() {
        cout << "this is children’s fuction! " << endl;
    }
};
int main(int argc, char * argv[]) {
    cout << sizeof(A) << "" << sizeof(B) << endl;
    return 0;
}

  • 12 12
  • 8 8
  • 9 9
  • 12 16


答案 A

考虑一下对齐,以及虚函数表




2.写出下列程序的运行结果。

#include "stdio.h"
int sum(int a)
{
    auto int c = 0;
    static int b = 3;
    c += 1;
    b += 2;
    return (a + b + c);
}
int main()
{
    int i;
    int a = 2;
    for (i = 0; i < 5; i++) 
    { 
        printf("%d,", sum(a)); 
    } 
} 


  • 6,8,10,12,14,
  • 8,10,12,14,16,
  • 10,12,14,16,18
  • 12,14,16,18,20

答案:B

水题。。。




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值