小编Yuv*_* Ng的帖子

int []中的未赋值

想知道在C++中int[]通常是什么值的未分配整数.

int arr[5];
arr[1]=2;
arr[3]=4;
for(int i=0;i<5;i++)
{
  cout <<arr[i] <<endl;
}
Run Code Online (Sandbox Code Playgroud)

它打印

-858993460
2
-858993460
4
-858993460
Run Code Online (Sandbox Code Playgroud)

我们知道阵列会在{?,2,?,4,?}哪里?不明.

什么会"?" 通常?

当我测试时,我总是得到负值.我可以假设在C++中,整数数组中的未分配元素总是小于或等于零吗?

如我错了请纠正我.当我在Java中学习时,未分配的数组元素将产生null.

c++ visual-c++

3
推荐指数
1
解决办法
3012
查看次数

如何在Java中获取数字的"位置"(例如,数十,数千等)

如何确定数字的位数并确定要运行的循环数?

例如,如果我有一个数组int[] a= {123,342,122,333,9909},int max = a.getMax()我们得到值9909.我想得到9909 的数字位值,这是第千位.

例如...

(number place value,number of loop to run)

(one,1 time)
(tenth,2 time)
(hundred,3 time)
(thousand,4 time)
(ten thousand,5 time)
(hundred thousand,6 time)
Run Code Online (Sandbox Code Playgroud)

这是我的代码,但是当它遇到整数之间的零时失败...

public static int getMax(int[] t,int n){
     int maximum = t[0];   // first value of the array
     int index = 0;
     int div=1;
     int numSpace=0;
     int valueTester=34;
     boolean done=false;

     for (int i=1; i<n; i++) {
       if (t[i] > maximum) {
         maximum = t[i];   // …
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×1

java ×1

visual-c++ ×1