关于C的基本问题 [英] Basic questions about C

查看:45
本文介绍了关于C的基本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在学习C语言,我有几个问题。我不是想用这些问题侮辱C或其他任何东西,他们只是老实说

我不能得到的东西。


似乎指向字符的指针就是你如何处理字符串,而指向char的指针的
指针只给你字符串数组。什么是

这个与字符串类型的语言的优势?


malloc分配内存的优点是什么? />
只为你做的语言?


静态内存分配与动态有什么关系?而且,

又一次,为什么一个人想要处理这个而不仅仅是拥有一台电脑

为你做这件事?特别是现在计算机拥有如此多的内存。


C语言是否介于汇编语言和大多数其他语言之间?就像在,C比其他大多数人更接近汇编语言吗?


谢谢。


格雷格

解决方案



" TefJlives" < gm ******** @ gmail.com写了留言


大家好,


我'我正在学习一点C,我有几个问题。我不是想用这些问题侮辱C或其他任何东西,他们只是老实说

我不能得到的东西。


似乎指向字符的指针就是你如何处理字符串,而指向char的指针的
指针只给你字符串数组。什么是

这个与字符串类型的语言的优势?



C所有意图和目的都没有字符串。一个字符串只是一个

字符数组,其中一个零字符作为字符串结尾的标记。

所以char * str =" Fred"

在str指向的地方声明''''''''''''''''''''''''''零''需要几个字符串,在数组中收集几个指针,然后给它们
piont。所以你需要一个额外的*。


优点是处理器不支持字符串,至少在

概率。所以你知道处理器正在做什么。


>

malloc分配内存的优点是什么,而

语言是什么只为你做这件事吗?



你知道程序正在做什么。因此,如果你想转移到一个内存很少的小型嵌入式平台,只要你不打电话给
malloc()就知道你的程序会运行。


>

静态内存分配与动态有什么关系?而且,

又一次,为什么一个人想要处理这个而不仅仅是拥有一台电脑

为你做这件事?特别是现在计算机有很多内存。



计算机现在几乎拥有无限的内存,因此使用静态内存区域的原因要少得多。 。不久之前,有一台电脑资源耗尽的真正威胁,所以为这个程序的独家计算机占用一大块内存是有意义的

使用。


>

C是否介于汇编语言和大多数其他的某些

意义上?就像在,C比其他大多数人更接近汇编语言吗?



是的。 C基本上是一个汇编程序的抽象,对

调用函数有一点支持。如果您了解汇编程序,通常可以查看一个

C程序并大致说出处理器将要执行的操作。然而,对于具有分支预测的非常奇特的处理器,

并行执行以及其他功能,这是不太真实的。


< blockquote> Malcolm McLean写道:


" TefJlives" < gm ******** @ gmail.comwrote:


>>静态内存分配与动态有什么关系?而且,
再次,为什么一个人想要处理这个问题而不仅仅是拥有一台电脑为你做这件事?特别是现在计算机有很多内存。



计算机现在几乎拥有无限的内存,因此使用静态内存区域的原因要少得多。 。不久之前,有一台电脑资源耗尽的真正威胁,所以为这个程序的独家计算机占用一大块内存是有意义的

使用。



空间不是问题,对象的生命周期是。


-

Ian Collins。


" TefJlives" < gm ******** @ gmail.com写信息

新闻:11 ********************** @ v33g2000cwv.googlegr oups.com ...


>

C语言介于汇编语言和某些语言中的大多数其他语言之间/>
感觉?如同,C语言比其他大多数人更接近汇编语言吗?



''C''编译非常好。


大多数数据类型,运算符和控制流构造C是非常接近机器指令集的
。即使指针和数组

操作也经常映射到一个或少量机器指令。这个

是设计的。


请注意,数据大小与平台有关。这是设计的。


将''C'描述为更高级别的汇编程序有点准确。它是
强烈朝着这个方向发展。


有了一台功能强大的机器,可以说大多数C编译器将在

大多数地方比汇编语言做得更好。


''C''非常适合编写操作系统内部和

性能关键系统。


似乎指向字符的指针就是你如何处理字符串,以及

指针指针char只给你一串字符串。什么是

这个与字符串类型的语言的优势是什么?



优势是无可比拟的残酷效率。


请注意,如果需要,您可以自由编写自己的字符串功能。

'''''''''''''''''''''''''''''''''''''''''''''

$


malloc分配内存的优势是什么?

只为你做的语言?



速度,控制。在为您分配内存的典型语言中(例如,典型的脚本语言),很难构建高级数据

结构。


静态内存分配与动态有什么关系?而且,

又一次,为什么一个人想要处理这个而不仅仅是拥有一台电脑

为你做这件事?特别是现在计算机有如此多的内存。



速度,控制,构建任意复杂数据结构的能力。


-

David T. Ashley(dt*@e3ft.com)
http://www.e3ft .com (咨询主页)
http://www.dtashley.com (个人主页)
http://gpl.e3ft.com (GPL出版物和项目)


Hi all,

I''m learning a bit about C, and I have a few questions. I''m not trying
to insult C or anything with these questions, they''re just honestly
things I don''t get.

It seems like pointers to chars are just how you deal with strings, and
pointers to pointers to char just give you arrays of strings. What is
the advantage of this vs. languages with a string type?

What is the advantage of things like malloc to allocate memory, vs.
languages that just do it for you?

What the heck is up with static memory allocation vs. dynamic? And,
again, why does one want to deal with this vs. just having a computer
do it for you? Especially now with computers having so much memory.

Does C lie somewhere between assembly language and most others in some
sense? As in, is C closer to assembly language than most others?

Thanks.

Greg

解决方案


"TefJlives" <gm********@gmail.comwrote in message

Hi all,

I''m learning a bit about C, and I have a few questions. I''m not trying
to insult C or anything with these questions, they''re just honestly
things I don''t get.

It seems like pointers to chars are just how you deal with strings, and
pointers to pointers to char just give you arrays of strings. What is
the advantage of this vs. languages with a string type?

C has to all intents and purposes no strings. A string is just an array of
chars with a zero char as a sentinel for string end.
So char *str = "Fred"
declares ''F'' ''r'' ''e'' ''d'' ''zero'' at the place pointed to by str.

If you need several strings, collect several pointers in an array and then
piont to them. So you need an extra *.

The advantge is that the processor has no support for strings, at least in
all probability. So you know what the processor is doing.

>
What is the advantage of things like malloc to allocate memory, vs.
languages that just do it for you?

You know what the program is doing. So if you want to move to a small
embedded platform with little memory, as long as you make no calls to
malloc() you know your program will work.

>
What the heck is up with static memory allocation vs. dynamic? And,
again, why does one want to deal with this vs. just having a computer
do it for you? Especially now with computers having so much memory.

Computer nowadays have virtually infinite memory so there is far less reason
to use static memory areas. Not too long ago there was a real threat of the
computer running out of resources, so it made sense to hog a chunk of memory
for the program''s exclusive use.

>
Does C lie somewhere between assembly language and most others in some
sense? As in, is C closer to assembly language than most others?

Yes. C is basically an abstraction of an assembler with a bit of support for
calling functions. If you know assembler, it normally possible to look at a
C program and say roughly what the processor will be doing. However that is
getting less true with very fancy processors with branch prediction,
parallel execution, and other features.


Malcolm McLean wrote:

"TefJlives" <gm********@gmail.comwrote:

>>What the heck is up with static memory allocation vs. dynamic? And,
again, why does one want to deal with this vs. just having a computer
do it for you? Especially now with computers having so much memory.


Computer nowadays have virtually infinite memory so there is far less reason
to use static memory areas. Not too long ago there was a real threat of the
computer running out of resources, so it made sense to hog a chunk of memory
for the program''s exclusive use.

Space isn''t the issue, lifetime of the object is.

--
Ian Collins.


"TefJlives" <gm********@gmail.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...

>
Does C lie somewhere between assembly language and most others in some
sense? As in, is C closer to assembly language than most others?

''C'' compiles EXTREMELY well.

Most of the data types, operators, and control flow constructs in ''C'' are
quite close to the machine instruction set. Even pointers and array
operations often map to one or a small number of machine instructions. This
is by design.

Notice that data sizes are platform-dependent. This is by design.

It is somewhat accurate to describe ''C'' as a higher-level assembler. It
goes strongly in that direction.

With a capable machine, it is fair to say that most ''C'' compilers will in
most places do a better job than you can in assembly-language.

''C'' is very suitable for writing operating system internals and
performance-critical systems.

It seems like pointers to chars are just how you deal with strings, and
pointers to pointers to char just give you arrays of strings. What is
the advantage of this vs. languages with a string type?

The advantage is unmitigated brutal efficiency.

Note that you are free to write your own string functionality if you want.
And the efficiency of ''C'' guarantees that it will probably work as fast as
anything built-in to the language would be.

What is the advantage of things like malloc to allocate memory, vs.
languages that just do it for you?

Speed, control. In a typical language that allocates memory for you (a
typical scripting language, for example), it is hard to build advanced data
structures.

What the heck is up with static memory allocation vs. dynamic? And,
again, why does one want to deal with this vs. just having a computer
do it for you? Especially now with computers having so much memory.

Speed, control, ability to build arbitrarily-complex data structures.

--
David T. Ashley (dt*@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)


这篇关于关于C的基本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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