由买买提看人间百态

topics

全部话题 - 话题: array
首页 上页 1 2 3 4 5 6 7 8 9 10 (共10页)
t****z
发帖数: 229
1
来自主题: Programming版 - address of an array
yes, even when you declared the parameter as an array
i**p
发帖数: 902
2
来自主题: Programming版 - Array in C
So based on the explaniation in this web page, I have following:
char abc[30];
abc reference to a has type ``pointer to char,'' and &abc is ``pointer to
array of 10 chars.''
we should use &abc for a string, but mostly we use abc. Please comment.
e******d
发帖数: 14
3
来自主题: Programming版 - Why Avoid array indexing. Use pointers.
Code optimization 有这么一条 Avoid array indexing, Use pointers. 为什么呢?不需要再算地址了?
还有 Use int (natural word-size of the processor) to store flags rather than char or short。就因为alignment?
t*****g
发帖数: 1275
4
来自主题: Programming版 - array allocation in c
Dynamic array on stack is allocated using calculated size instead of 'pre-
calculated' or 'hard-coded' size; The allocation is not different than
moving the stack pointer though. The following assembly code may show you
how it works (solaris on x86)
...
leal -0x8(%ebp),%eax ; pipe scanf output to this address
...
call -0x23d ; call scanf
movl -0x8(%ebp),%eax ; obain variable 'n' and save it to %eax
...
subl %eax,%esp ; grow the stack pointer
z********0
发帖数: 9013
5
来自主题: Programming版 - C array
嗯,不错,学到新东西了,本以为C就那样了,没想到还有新花样
和malloc相比是方便些了,不用惦记释放了,不过万一Malloc失败,还可以返回null来
告诉Programmer,还有一层Safety Net, 可要是Variable Length Array失败,比如参
数太大或者太小(负数),估计就直接Seg Fault了,程序都捕捉不到,这样的潜在BUG
在Testing的时候也未必能暴露出来
O*******d
发帖数: 20343
6
来自主题: Programming版 - C array
如果是multiple platform, 就必须遵守标准的C. array size必须是compile time
constant. 我的工作给多个平台写驱动, 公司规定必须这样作,否则就不能在所有平
台上汇编。
s********z
发帖数: 5411
7
来自主题: Programming版 - create and display BMP image from 2-D array
Hello, I am new to C++ and MFC and was trying to create a true color bmp
from R,G,B channel images and display it. Now I have three band images Rband
[width][height], Gband[width][height], Bband[width][height]. All three bands
are 1 byte 2-D array and are known. Now I am wondering how to I fill the
memory pic allocated below to be able to display the image.
struct
{
BITMAPINFOHEADER bih;
unsigned long Colors[256];
}
bilutc; // current BITMAPINFO with LUT values
if(bC
G***G
发帖数: 16778
8
来自主题: Programming版 - how to assign value to a string array
a string array with unknown length
how to assign value to it?
string [] a;
a[0]="good";
a[1]="morning";
why the above is wrong?
M*m
发帖数: 141
9
void f(int a[]){
// when I try to get the size of a, it is always 4,
// how can I get the actual size of the array?
}
int main(){
int a[] = {1, 2, 4, 5};
sizeof(a) // 16;
f(a)..
}
M*m
发帖数: 141
10
yeah, that works. but is there a way that I can get the size of a within f,
using sizeof... so that I do not have to pass the size of an array?
b**a
发帖数: 1118
11
Design an efficient algorithm to sort elements in a stack in either
ascending/descending order, using only pop(), top(), push(), isEmpty(),
isFull(). Do not use any auxiliary stacks or arrays.
I found this question in jobhunting board. the anwser given by a niu ren is
Is this right? Does not look like right one.Thanks.
w***g
发帖数: 5958
12
来自主题: Programming版 - C++ array new一问
typedef float Feature[100];
vector a(100);
这样貌似不行,因为Feature是个array, 要用new []而不是new。不知道有没有什么统一
的做法。
f******y
发帖数: 2971
13
来自主题: Programming版 - C++ array new一问
do you want a 2D array?

统一
b******n
发帖数: 592
14
you can always use a simple script to generate C++ array and paste it in you
r source code
z**k
发帖数: 378
15
来自主题: Programming版 - C++ class怎么定义double array啊
我有个class Matrix,我想定义一个operator,功能类似于double array:
Matrix m;
...
m[1][2]; //这个operator要怎么定义呢?
对不起,我小弱
f********f
发帖数: 475
16
来自主题: Programming版 - 怎样将array^转换成string?
想将array的每个item从unsigned char变成Hex, 然后concatenate一起变成string.怎
么做呢? 谢谢!
g****g
发帖数: 1828
17
const int nbins = 13;
double xbin[nbins+1];
for (int i=0;i xbin[i]= 10.0*i;
here's the message, but the line number is incorrect; it's far from the line
where this array is located.
Limitation: Statement too long FILE:drawRatios4.C LINE:96
cint: Security mode 0x7:0x2 *** Fatal error in interpreter... restarting
interpreter ***
*** Fatal error in interpreter... restarting interpreter ***
g****g
发帖数: 1828
18
多谢大家! 我找到了错误的原因。忘了说,上面那段code原来全在global variable的
部分。
我这样做就没问题了,把他们放在不同的地方:
//这部分仍然放在global
const int nbins = 13;
//这部分转移到第一个被调用的function的最前面部分。
//(其实任何用到该array前都可以,我觉得。但放在开头清楚些。)
double xbin[nbins+1];
for (int i=0;i xbin[i]= 10.0*i;
M***7
发帖数: 2420
19
来自主题: Programming版 - Randomization of an array
Is there any algorithm to randomize an array without bias of time?
Thanks in advance.
r****t
发帖数: 10904
20
来自主题: Programming版 - Randomization of an array
The indexing arrays as vectors should have stationary distribution?
r****t
发帖数: 10904
21
来自主题: Programming版 - 问个基本 C array 问题
这两个写法有啥不同?
Point p1,p2 = points[i], points[++i];

Point p1 = points[i];
Point p2 = points[++i];

这两个都是在一个 loop 里面,循环变量是 i. points 是一个 array.
编译的时候前面的写法有 warning:
variable "points" was declared but never referenced.
后面写成两行就没问题了。
t****t
发帖数: 6806
22
来自主题: Programming版 - 如何 initialize array member?
first of all, you can not copy array by using numbers(numbers). must use
memcpy or std::copy.
second, if you declare ctor as A::A(float numbers[N]), it is equivalent to A
float[1] without compiling errors, which may not be desirable. depending on
your requirement, you may want to use
A::A(const float (&numbers)[N])
as ctor, which preserves length information and enforces that you can only
send in float[N] at compile time.
below.
p***o
发帖数: 1252
23
来自主题: Programming版 - C++里get array size的问题 (转载)
Most likely they won't work under the situation LZ needs them to work,
e.g. after passing the array to a function ...
BTW, I don't see the advantage of the template approach compared to
the sizeof/sizeof approach. Is it more robust?
t****t
发帖数: 6806
24
来自主题: Programming版 - C++ Q09: delete dynamic array
short answer: polymorphism and array do not mix.
long answer: read effective c++.
c**********e
发帖数: 2007
25
来自主题: Programming版 - C++ Q09: delete dynamic array
thrust is right.
b) It invokes undefined behavior.
This is correct. When deleting an array, the dynamic and the static type of
the object must be the same, or the behavior is undefined (C++ Standard 5.3
.5/3).
c**********e
发帖数: 2007
26
It looks that`in Java, there is a function Split which convert a string to a
string array. I wonder if we could do the same in C++. How to do the
conversion?
string MyString = "value1;value2;value3;value4;"
string[] MyStringArray = MyString.Split(';');
MyStringArray[0] (would give value1)
MyStringArray[1] (would give value2)
etc......
j********g
发帖数: 44
27
It is said that statically allocated array must have length which should
be const or const expression.
I could not understand why the following works just fine:
#include
using namespace std;
int main()
{
int m,n;
cin>>m>>n;
double a[m][n], x[n], b[m];
for(int i=0;i b[i]=i*i;
for(int i=0;i cout<
int staff_size=27;
double salary[staff_size];
return 0;
}
g*****g
发帖数: 34805
28
Of course array, and + operation is not faster with linked list,
as you have to duplicate the storage.
If A = B + C, A shouldn't share any storage with B or C
s******e
发帖数: 493
29
It really depends on how often you want to do those operations and which
language.
If C/C++, or maybe any languages where array must be in a consective memory
space, as you said linked list will be faster on "+" operation. but random
access will be slow. I will vote for linked list if you must choose from two.
Or you can think from a different direction, like java, create a string
constant pool, and make string objects immutable.
t****u
发帖数: 8614
30
这个东西,就算要reinvent the wheel。
最简单的方法就是refer to std::string,那边是array的。
如果linked list好,早就一大堆library用linked list来实现string了。
这些都是前人的智慧总结。
s*****w
发帖数: 1527
31
assume i have a array {0, 5, 2, -1, 3, 6}
want to find the index for 2,
how to do it pls ?
c**t
发帖数: 2744
32
Array class exists in all version .Net FW. check out the help.
s****n
发帖数: 700
33
来自主题: Programming版 - help about convert a char array in c
char text[64] = "SPY 121231C00095000";
Symbol - 6 bytes
Year - 2 bytes
Month - 2 bytes
Day - 2 bytes
Call/Put Indicator - 1 byte
Strike Dollar - 5 bytes
Strike Decimal - 3 bytes
I want to convert it to the format like "SPY,C,121231,95.0"
The only way I know is to loop the array and set some if statement to get
rid of empty char for Symbol, and get rid of 0 char for strike.
Is there any more efficient way to handle the case. Thank you very much.
i****a
发帖数: 36252
34
【 以下文字转载自 DotNet 讨论区 】
发信人: iMaJia (iMac,iPod,iPad,i馬甲), 信区: DotNet
标 题: How to compare data in an Array and in Xml
发信站: BBS 未名空间站 (Wed Feb 8 17:25:48 2012, 美东)
I am coding in C# .NET 3.5
Let's say I have a List, and an XML file with list if items.
What I want to do is compare the values of the two lists, and get the
difference.
I want two results, 1. items in List but not in XML, 2. items in XML but
not in List.
I can only think of looping through the List against XML, and another loo... 阅读全帖
w****i
发帖数: 964
35
Suppose the array is a1...a9
to iterate it in this order: a1, a9, a2, a8, a3, a7, a4, a6, a5
how to write it in a simple form, say a for loop?
c**********e
发帖数: 2007
36
来自主题: Programming版 - python: how to use an array as an argument
For example, we have function f(arr), arr an array with index 0 to n-1.
def f(arr)
or def f(arr, n) ... This is C++
or any other way? Thanks.
p*********t
发帖数: 2690
37
为啥matlab一直用列优先存储来存储array? 谁能讲讲这个列优先存储的来龙去脉?
d*****l
发帖数: 8441
38
拜托,懂一点儿数学吧。
Array在数学上就是列向量。数学上对向量的定义很不幸就是列向量,而把
行向量定义为向量的转置。在此定义之下,矩阵大多情况下是表示为多个列向量的。
说白了,就是数学习惯问题。
要怪就只能怪线性代数和矩阵论中的约定俗成的东西比C语言出现的要早。
j******a
发帖数: 1599
39
来自主题: Programming版 - zero-sized array vs pointer
http://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html#Zero-Length
zero-sized array一般我们都是用来做place holder的,但是为啥不用一个void的
pointer呢? 区别在那里阿?
f*******n
发帖数: 12623
40
来自主题: Programming版 - zero-sized array vs pointer
array and pointer are completely different
t****t
发帖数: 6806
41
事实上我刚才看花眼了, 第二个不能说是错, 但是类型不匹配. C可以强制转换.
char (*str)[]的意思是pointer to array of char, 而"ABC"被强制转换了.
G****u
发帖数: 51
42
问题是为啥fun2 总能输出ABC,而fun1时而能输出ABC(gcc), 时而输出garbage? array
在C里面到底是怎么给造出来的, 一下子可以等同与pointer, 一下子不能, 这背后的原
因是啥.

ANY
t****t
发帖数: 6806
43
fun2没有错, 所以总能输出ABC, 虽然你把好好的函数写成了一滩那什么.
fun1有错, 能不能输出ABC要看天意.
至于array和pointer的关系, 请仔细阅读C FAQ第6章.
t****t
发帖数: 6806
44
strictly speaking, it's not equivalent. but in your case it's about the same.
as i said, char (*str)[] means "pointer to array of char", but that doesn't
matter as long as it is a pointer. let's say it's "pointer to T". then
forcefully convert string literal "ABC" (which has type "pointer to char")
to "pointer to T", then forcefully convert to back to "pointer to char". the
result will be the original pointer to char. it doesn't matter what is T,
wha matters is, str is a pointer to something.
r***t
发帖数: 21
45
in fun1, str is a local char array which has "ABC", the space is local stack.
in fun2, str is a poiner, "ABC" is treated as constant string, which will be
allocated from global space.
e******o
发帖数: 757
46
来自主题: Programming版 - 问一个defining array 的问题
当要define 一个array 的时候, C++ primer是这样写的: The dimension must be a
constant expression whose value is greater than or equal one. 但我发现网上
好多代码都不是这样的,但是能编译通过。
比如一个function,
int largestRetangleArea( vector &height)
{
int area[height.size()];
//some operations;
//return a value;
}
编译是也能通过。请问一下为什么呢?
谢谢。
f*******n
发帖数: 12623
47
来自主题: Programming版 - 问一个defining array 的问题
但是他用的是C++。variable-length array不在C++标准里
b***i
发帖数: 3043
48
For interview, use keyword static before the array
W***o
发帖数: 6519
49
比如我有一个这样的array {1, 2, 3, 3, 3, 3, 5, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9}
,我希望找出里面的duplicate segment {3, 3, 3, 3} {8, 8, 8, 8, 8} {9, 9, 9, 9}
我的想法是用两个指针i,j。i 初始化在index 0, j 在 N - 1最后一个index. 保持i不
懂,用j从用往左扫描,如果没找到,让j停在i + 1的位置,然后increment i to i+1,
j to N-1. 如此反复,如果j找到了一个duplicate segment的最右端, 此时test[i] =
= test[j] true,这个时候打印出这个segment. 然后increment i to j + 1, j to N-
1,再反复这个过程直到 i = j然后跳出循环。
最近脑袋比较浆糊,写了下面这个代码,但是不work,请各位来点播一下思路。谢谢了
int[] test = new int[] {1, 2, 3, 3, 3, 3, 5, 6, 8, 8, 8, 8, 8, 9, 9, ... 阅读全帖
W***o
发帖数: 6519
50
终于work了,但是我的方法可能比较慢,array access 是不是太多了,有更高效的吗
?不能用太高级的API,因为作业规定:
int[] test = new int[] {1, 2, 3, 3, 3, 3, 5, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9};
int i = 0;
int j = test.length - 1;
int[] copySegment;

while (i < test.length)
{
while (j > i)
{
if (test[j] == test[i])
{
for (int k = i; k <= j; k++)
System.out.print(test[k] + " ");
Syst... 阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 (共10页)