[questions] 11.1 ~ 11.8

本文探讨了快速编程时如何平衡代码质量、编程时间和程序性能的问题,并讨论了解耦模块的方法及面向对象编程中成员变量的使用建议。

Please add your questions below in format:
<name>  <book and chapter>  <questions>
! You'd better make a backup before posting
---------------------------------------------------------------------------------

[Hui, CC/5] Sometimes we need program fastly. Then, how to make a balance between quality of code, programming time and performance of program?
[Hui, CC/5] Keep coupling loose is a good idea. But how to achieve it? It's quite natural for me to write a bad coupled module.
[Hui, CC/10] Any suggestion of member variable in the OOP. "public", "protected" and "private" make me mad!
[Hui, CC/*] PS. I've read all the book <Code Complete II>. It's justc a collection of tips. As a new asker, I feel hard to ask more questions...

“Question *questions”是一个指针数组的声明方式,其中“Question”是一个自定义的数据类型(结构体或类),而“*questions”则表示一个指向该类型的指针数组。这意味着你可以使用这个指针数组来存储多个“Question”类型的对象。 具体来说,这种声明方式通常用于需要动态分配内存或处理不定数量对象的情况。通过指针数组,你可以方便地管理和操作多个“Question”对象,例如在内存中分配、释放、访问和修改。 以下是一个简单的示例,展示了如何使用指针数组来存储和管理多个“Question”对象: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> // 定义Question结构体 typedef struct { char *text; int id; } Question; // 函数声明 Question* createQuestions(int count); void printQuestions(Question *questions, int count); void freeQuestions(Question *questions, int count); int main() { int count = 3; Question *questions = createQuestions(count); printQuestions(questions, count); freeQuestions(questions, count); return 0; } // 创建Question对象 Question* createQuestions(int count) { Question *questions = (Question*)malloc(count * sizeof(Question)); if (questions == NULL) { printf("Memory allocation failed\n"); exit(1); } for (int i = 0; i < count; i++) { questions[i].id = i + 1; questions[i].text = (char*)malloc(100 * sizeof(char)); if (questions[i].text == NULL) { printf("Memory allocation failed\n"); exit(1); } sprintf(questions[i].text, "Question %d", i + 1); } return questions; } // 打印Question对象 void printQuestions(Question *questions, int count) { for (int i = 0; i < count; i++) { printf("ID: %d, Text: %s\n", questions[i].id, questions[i].text); } } // 释放Question对象占用的内存 void freeQuestions(Question *questions, int count) { for (int i = 0; i < count; i++) { free(questions[i].text); } free(questions); } ``` 在这个示例中,我们定义了一个“Question”结构体,并创建了一个指针数组来存储多个“Question”对象。我们还实现了创建、打印和释放“Question”对象的函数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值