char firstName[32];
我的理解是,每一焦炭都记忆犹新。 因此,上面有32个记忆tes?
我没有一位也记忆犹新的人,或者这只是32个 by子?
char firstName[32];
我的理解是,每一焦炭都记忆犹新。 因此,上面有32个记忆tes?
我没有一位也记忆犹新的人,或者这只是32个 by子?
No, that takes up exactly 32 bytes of memory. There is no pointer.
这常常是一个混淆的领域,因为一个阵列的名称对一个“char*”保持沉默。
char* fname = firstName;
因此,firstName
可以是const char*
,但其本身不是“char*变数”。 这完全是:
int x = 5;
<代码>x为无变量,占用空间。 另一方面,5
仅是固定型值。 它没有空间;它只是价值。
它有32个记忆。 在国内,所有问题都得到解决。 变数只能用于我们的理解。
这只是32个tes。 阵列的名称有时是acts,如,指第一点,但不是。
这涉及32个tes。 它将拥有31个果园(另一个星号是无固定装置)。
声明char firstName[32]
在tack上设定了32个特性,即32个特质。 编辑们知道,这套车上是哪里的。 汇编者将难以将阵列的地址编码为使用该信的操作;没有必要储存该信标。
必须指出,如果你试图将这一阵列作为功能理由加以利用,就会将阵列降为pointer/strong>,因为C++确实允许按价值穿过原始阵列。 多数新到C++的人预计会通过一个阵列的副本。
当你需要时,有两种途径,例如,有32条由tes来储存你的数据。 两种版本的差异:
// version 1
char *firstName = new char[32];
// version 2
char firstName[32];
也就是说,就第1版而言,你在
<>strong>sizeof (FirstName )
有趣的是,回归的规模是多少,这是第1版和第32版的果园(取决于你的系统和编辑)的规模。 2. 结 论 考虑到另一个用户提到的情况,通过firstName功能将其降级为点人。
Complementing the answers above:
A pointer to char occupies 4 bytes in the 32-bit architecture, whereas in the 64-bit architecture it occupies 8. In the example, it occupies 4.
#include <stdio.h>
#include <stdlib.h>
#define SIZE 32
int main()
{
char array[SIZE];
char *ptr = (char*)array;
printf("
size of array: %i bytes", sizeof(array));
printf("
size of pointer: %i bytes", sizeof(ptr));
printf("
address array on the stack: %p", &array);
printf("
address reference: %p", ptr);
printf("
address pointer to array on the stack: %p", &ptr);
/*
1 char ----- 1 byte
32 characters ---- 32 bytes
*/
return 0;
}
我们还可以为32个前沿阵列分配空间:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 32
int main()
{
char array[SIZE];
char *malloc_pointer = (char*)malloc(sizeof(array)); // a pointer on stack pointing out 32 bytes on heap
printf("
address malloc_pointer on the stack: %p", &malloc_pointer);
printf("
size of pointer to heap: %i bytes", sizeof(malloc_pointer));
free(malloc_pointer); // clean
return 0;
}
在试算本中,还储存在阵列之外(一些汇编者)的陶器,在阵列后检查写作。 在释放版本中,应当有32个tes子加一个 in子(可能是)储存地址。
I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...
I have been searching for sample code creating iterator for my own container, but I haven t really found a good example. I know this been asked before (Creating my own Iterators) but didn t see any ...
Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...
I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?
Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...
Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?