C/C++编程中的常见问题与技巧
在C/C++编程领域,存在着一些常见的问题和实用的技巧,这些内容对于开发者来说至关重要。下面将详细介绍几个关键方面。
1. 经典结构体错误
在C/C++编程中,结构体是一种常用的数据类型。但有时会出现经典的结构体错误。
最初定义一个结构体 test :
struct test
{
int field1;
int field2;
};
同时有对应的 setter 和 printer 函数:
void setter(struct test *t, int a, int b)
{
t->field1=a;
t->field2=b;
};
#include <stdio.h>
void printer(struct test *t)
{
printf ("%d\n", t->field1);
printf ("%d\n", t->field2);
};
当在结构体中添加一个新的字段时:
struct test
{
int field1;
int inserted;
int field2;
};
并且修改了 setter
超级会员免费看
订阅专栏 解锁全文
11万+

被折叠的 条评论
为什么被折叠?



