练习 C++ 的好资源数组和指针
我正在从书本上学习C++。我想我理解基本概念,但是这本书没有提供太多练习。我想了解网站、开源项目或任何提供练习或源代码的资源,我可以阅读这些资源并亲自接触 C++ 数组和指针。
I'm learning C++ from book. I think I understand basic concept but the book provide not much exercise. I want to know website, opensource project or any resource that provice exercise or souce code that I can read and get my hand dirty with C++ Arrays and Pointers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当涉及到指针和数组时,C 和 C++ 在概念上没有区别。练习 K&R 问题。它们很好而且很全面。
其中提供的理论足以让您开始了解与指针和数组相关的复杂逻辑。
There is conceptually no difference between C and C++ when it comes to pointers and arrays.Practice K&R questions. They are good and comprehensive.
The theory provided in it is good enough to get you started with complex logic related to pointers and arrays.
引用和取消引用是 C++(和 C)开发人员的主要工作。人们常说,只要有足够的间接级别,任何问题都是可以解决的。这是在托管语言中得出的逻辑结论,默认情况下将对象视为引用,但没有像 C 或 C++ 这样的非托管语言的更细粒度的控制。托管语言的开销部分是由于这种默认的最大间接性,但主要是由于垃圾收集,这就是为什么间接性对于更高效的解决方案如此有利。
查看机器指令或汇编代码以了解指针的功能和范围。
至于数组,根据我的经验,指针是传递它们的最佳方式。如果我更有耐心,我可能会发现数组也作为引用传递,并且作为参数同样有效,但是 C 并没有采用这种与预期行为的非标准偏差,这也是我在 C/Java/C++/ 中学到的东西C# 语言家族。
此外,数组几乎仅限于静态大小调整,而指针则不然。昨晚我看到一个关于 C99 数组的问题,表明动态数组是该标准的一部分,但我必须对它们的动态程度保持谨慎。在不使用变量定义数组大小的情况下,在正确的时间执行初始化(我的意思是大小定义)通常很棘手 - 这就是 C99 问题所确定的,初始化中的变量。
抱歉缺少链接,我之前在这里观察到它们可能被描述为缺乏答案。
Referencing and dereferencing are the bread and butter of C++ (and C) developers. It is often said that any problem is solvable given sufficient levels of indirection. This is taken to its logical conclusion in managed languages which treat objects as references by default but without the finer grained control of an unmanaged language like C or C++. Managed languages overhead is partly due to this default, maximum indirection, but mostly due to Garbage Collection, which is why indirection is such a boon to more efficient solutions.
Have a look at machine instructions or assembly code to appreciate the power and scope of pointers.
As for arrays, it has been my experience that pointers are the best way to pass these around. Had I more patience I might discover that arrays are passed as references also, and equally efficient as parameters, but C doesn't employ such non standard deviations from expected behaviour and is what I cut my teeth on in the C/Java/C++/C# family of languages.
Also arrays are pretty much limited to static sizing, whereas pointers are not. I saw a question about C99 arrays last night that indicated dynamic arrays were part of that standard but I'd have to be cautious regarding just how dynamic they are. It is often tricky to get the initialization (I mean size definition) performed at the right time without using a variable to define the array size- this was what the C99 question identified, a variable in that initialization.
Sorry for lack of links, I've observed here before that they might be described as poor for an answer.