为什么此代码段在C中不起作用?
问题描述:
它说str未初始化。
It says "str" is not initialized.
展开 | 选择 | Wrap | 行号
答
C(和C ++)按值传递参数,C甚至不能通过引用传递(C ++可以)。
亲切的问候,
Jos
C (and C++) pass parameters by value, C can''t even pass by reference (C++ can).
kind regards,
Jos
>
但我正在传递一个地址。你可以在C中做到这一点。例如,这有效:
But I''m passing an address. You can do that in C. For example, this works:
展开 | 选择 | Wrap | 行号
@DelphiCoder
您在此处传递地址;该函数操纵该地址指向的对象。这与你的第一个例子不同。想一想:C按值传递参数;这就解释了这一切。
亲切的问候,
Jos
@DelphiCoder
You are passing an address here; that function manipulates the object pointed to by that address. That is entiry different from your first example. Think of it: C passes parameters by value; that explains it all.
kind regards,
Jos