我应该如何学习C?

发布于 2024-07-06 05:04:43 字数 1560 浏览 5 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

他是夢罘是命 2024-07-13 05:04:43

几年前,我的一个朋友问了我同样的问题:“我如何学习 C?” 我告诉他写一个设备驱动程序。

想象一下当他真的这么做时我的惊讶。

Several years back, a friend of mine asked me that same question: "How do I learn C?" I told him to write a device driver.

Imagine my surprise when he actually did it.

若有似无的小暗淡 2024-07-13 05:04:43

有点偏离主题,但既然你提到你的背景是数学和统计,你应该尝试一下欧拉项目。 有超过 200 个数学/统计相关问题可供解决。 此外,一旦找到解决方案,您可以查看问题论坛以了解其他人如何解决相同的解决方案。 非常方便查看其他人如何解决问题...而且启动起来很有趣!

www.projecteuler.net

Somewhat off topic, but since you mention your background is in Math and Stats your should try your hand at Project Euler. There are over 200 math/stat related problems available to solve. In addition, once you arrive at a solution, you can view the problem forum to see how others solved the same solution. Very handy for seeing how others solve the problem... and fun to boot!

www.projecteuler.net

翻身的咸鱼 2024-07-13 05:04:43

我和你有相似的背景。 我使用 Python 为我的博士研究以及网络编程进行大量数学和数据分析。 不同之处在于我是在 90 年代首先学习 C 的。

如果您可以为 Python 编写 C 扩展,那么我想说您对 C 的优点有很好的把握。 在我看来,如今的 C 最适合两件事:

  • 编写与硬件交互的低级软件。
  • 编写执行重复、乏味、CPU 密集型工作的代码(数学、XML 解析等)……也许可以作为高级语言的扩展。

当然,许多高级应用程序也是用 C 语言编写的,特别是在我发现的 Linux 下,但在很大程度上,这些应用程序并不是真正用 K&R 的“基本”C 语言或标准库编写的。 ,他们使用 Glib、wxWindows、Apache Portable Runtime 等框架,这些框架都使用某种面向对象的结构或约定,并且通常抽象出 C 的一些基本内存管理细节。

相反 我认为,要让您的 C 技能在当今的编程语言环境中发挥作用,主要是进行低级工作,或者熟悉这些高级框架之一。 我个人非常喜欢 Glib 和 GTK 库,因为它们使用非常动态面向对象的模型(很像 Python),而不妨碍您使用 C 的低级功能。

I have a similar background to you. I use Python to do a lot of math and data analysis for my PhD research, and also for web programming. The difference is that I learned C first, way back in the 90s.

If you can write C extensions for Python, then I'd say you have a pretty good handle on what C is good for. In my opinion, C today is best-suited for two things:

  • Writing low-level software that interacts with hardware.
  • Writing code that does repetitive, tedious, CPU-intensive stuff (math, XML parsing, etc.)... perhaps as an extension for a higher-level language.

Of course a lot of higher-level applications are also written in C, especially under Linux I've found, but in large part these aren't really written in the "bare-bones" C of K&R or the standard library. Rather, they use frameworks like Glib, or wxWindows, or the Apache Portable Runtime, or others, which all put use some kind of object-oriented structure or conventions, and often abstract away some of the basic memory-management details of C.

So I think that making your C skills useful in today's programming language environment is largely about doing low-level work, or becoming familiar with one of these higher-level frameworks. I personally like the Glib and GTK libraries a lot, since they use a very dynamic object-oriented model (a lot like Python) without preventing you from using the low-level features of C.

却一份温柔 2024-07-13 05:04:43

在日常工作中查找或定义问题,并强迫自己使用 C 而不是 Python 来解决它。 这将迫使你学习这门语言,同时保持问题与你平时所做的事情相关。

Find or define a problem in your day-to-day work and force yourself to solve it using C instead of Python. That will force you to learn the language while keeping the problem relevent to what you normally do.

旧时浪漫 2024-07-13 05:04:43

实现虚拟机(例如 JVM)。

Implement a virtual machine (the JVM, for example).

眼趣 2024-07-13 05:04:43

查看《Learn C the Hard way》,这是一本免费电子书,其中包含许多 C 代码示例和练习,以便您学习。

http://c.learncodethehardway.org/

check out learn C the hard way, it's a free ebook which takes you through many examples of C code and exercises in order for you to learn.

http://c.learncodethehardway.org/

昔日梦未散 2024-07-13 05:04:43

您可以为一种简单的语言编写一个解释器。 使用 Flex/Bison。 使其成为多线程等。这很有趣并且往往会大量锻炼指针。 我为学校项目写了类似的东西:一种基于简单堆栈的语言,具有两种不同的垃圾收集器、TwoSpace 和并发版本。 蛮好玩的。 并且可以作为第一个比“hello, world”更大的 C 程序!

You could write an interpreter for a simple language. Use flex/bison. Make it multithreaded etc. This is fun and tends to exercise pointers a lot. I wrote something like that for a school project: A simple stack based language with two different garbage collectors, TwoSpace and a concurrent version. That was fun. And doable as a first ever c program bigger than "hello, world"!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文