什么人很难找到关于C指针? [英] What do people find difficult about C pointers?

查看:99
本文介绍了什么人很难找到关于C指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从此处发布问题的数量,很明显,人们让周围指针和指针运算他们的头上时,有一些pretty基波的问题。

From the number of questions posted here, it's clear that people have some pretty fundemental issues when getting their heads around pointers and pointer arithmetic.

我很好奇,想知道为什么。他们从来没有真正引起了我的大问题(虽然我第一次了解他们早在新石器时代)。为了写这些问题更好的答案,我想知道是什么人觉得困难。

I'm curious to know why. They've never really caused me major problems (although I first learned about them back in the Neolithic). In order to write better answers to these questions, I'd like to know what people find difficult.

所以,如果你使用指针挣扎,或者你最近是却突然知道了,是什么导致你的问题指针方面?

So, if you're struggling with pointers, or you recently were but suddenly "got it", what were the aspects of pointers that caused you problems?

推荐答案

我怀疑人们在他们的答案会有点太深了。调度,实际的CPU运算或汇编级的内存管理的理解是不是真的需要。

I suspect people are going a bit too deep in their answers. An understanding of scheduling, actual CPU operations, or assembly-level memory management isn't really required.

当我在教学中,我发现学生的理解下面的孔是问题的最常见来源:

When I was teaching, I found the following holes in students' understanding to be the most common source of problems:


  1. 堆VS栈存储。这只不过是惊人的,有多少人不明白这一点,即使在一般的意义上。

  2. 堆栈帧。就在堆栈的局部变量专用部分的一般概念,它是一个'堆'...可以放心地留到细节,如积攒的返回地点,异常处理程序的详细信息,以及previous寄存器的原因沿有人试图建立一个编译器。

  3. 内存内存是铸造只是改变其经营者或者多少空间的版本的编译器给出了特定内存块。你知道你在处理这个问题时,人们谈什么(原始)变量X的真正的是。

  1. Heap vs Stack storage. It is simply stunning how many people do not understand this, even in a general sense.
  2. Stack frames. Just the general concept of a dedicated section of the stack for local variables, along with the reason it's a 'stack'... details such as stashing the return location, exception handler details, and previous registers can safely be left till someone tries to build a compiler.
  3. "Memory is memory is memory" Casting just changes which versions of operators or how much room the compiler gives for a particular chunk of memory. You know you're dealing with this problem when people talk about "what (primitive) variable X really is".

我的大部分学生都能够理解的内存块,在当前范围堆栈通常局部变量部分的简化图。一般给予明确的虚构地址到不同的位置有帮助。

Most of my students were able to understand a simplified drawing of a chunk of memory, generally the local variables section of the stack at the current scope. Generally giving explicit fictional addresses to the various locations helped.

我总结猜,我说,如果你想了解的指针,你必须了解变量,他们实际上是在现代架构。

I guess in summary, I'm saying that if you want to understand pointers, you have to understand variables, and what they actually are in modern architectures.

这篇关于什么人很难找到关于C指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆