item有值,但在Uint8Array中返回'undefined'(item has value but in Uint8Array return 'undefined')
嗨,我有这样的
Uint8Array
var ar = new Uint8Array(); ar[0] = 'G'; ar[1] = 0x123;
第二个索引是一个十六进制数,我想检查
ar[1]
是否大于零或不是,所以我写这个代码:if(ar[1] > 0){ console.log("OK"); } else{ console.log("NOP") }
但如果我写
console.log(ar[1])
我得到'undefined'。 这是我创建的一个简单的jsbin 。hi i have
Uint8Array
like thisvar ar = new Uint8Array(); ar[0] = 'G'; ar[1] = 0x123;
the second index is a hexa decimal number and i want to check
ar[1]
is grater than zero or not so i write this code :if(ar[1] > 0){ console.log("OK"); } else{ console.log("NOP") }
but if i write
console.log(ar[1])
i get 'undefined'. this is a simple jsbin that i created.
原文:https://stackoverflow.com/questions/45343505
最满意答案
如果在扫描阵列期间从未设置过
mini
,则minimum
函数可能会返回未初始化的值。 我不确定你的逻辑应该是什么,但也许你应该在你的函数顶部初始化mini = 0
或做其他事情以防止这种情况发生。 您没有指定给定矩阵中应该包含的内容,但作为示例,所有零的矩阵将触发此行为。Your function
minimum
could possibly return an uninitialized value, ifmini
was never set during your scan of the array. I'm not sure what your logic is supposed to be, but perhaps you should initializemini = 0
at the top of your function or do something else to prevent this from happening. You didn't specify what was supposed to be in the given matrix, but as an example a matrix of all zeroes would trigger this behavior.
相关问答
更多-
CodeChef上的TimeOut(TimeOut on CodeChef)[2022-07-31]
当x == 0时,你的sol不会终止。 当x为1时,它很好,因为x2, x3, x4都是0,并且它们的和小于x ,这意味着第二个保护是真的,没有递归。 但是,当输入为0时,递归情况会启动,并且它永远不会终止。 Your sol doesn't terminate when the x == 0. When x is 1 it is fine because all of x2, x3, x4 are 0, and their sum is less than x, meaning the second gu ... -
好吧,一个代码,这样的代码: ++*p++应该避免,因为它通常很难阅读。 其次,问题是您正在修改字符串文字 。 这是未定义的行为。 不要这样做。 相反,将您的声明更改为: char p[] = "hai friends"; char *p1; 并修改你的代码: int main() { char p[] = "hai friends"; char *p0,*p1; p0 = p; p1 = p; while(*p0 !='\0') ++*p0++; pri ...
-
第一步,从你称之为“re2”库的名称和部分来判断(这是非常着名的我不知道它;虽然它在Debian中,似乎没有任何东西需要它)是一个正则表达式库。 你已经在Python的re模块中有一个非常灵活的了。 其次, ctypes是本机库的不安全接口; 你需要完全正确地完成所有事情,这意味着理解底层类型系统,包括可以分配或释放内存以及由哪些例程执行的事情。 它的正常用例是包装具有C接口的库而不编写任何非Python代码。 在这种情况下,内存分配应该很容易,因为你只是返回一个bool并且不保留字符串引用。 但最重要的是 ...
-
putc给出分段错误?(putc giving segmentation fault?)[2022-07-24]
你必须将ch声明为int 。 否则,当出现字符ÿ时,文件的处理将停止。 char只能使用256个不同的值,这对于256个不同的符号+ EOF字符是不够的。 EOF是-1 ,当被视为int时相当于4,294,967,295 ,但当被视为char时它相当于255 。 如果您的输入文件包含字符ÿ (当被视为有signed时基本上为-1或255 ),则语句ch == EOF将变为true并且您的while循环将中断。 这与你的错误无关 ,但重要的是...... 如果程序崩溃,它会尝试读取/写入NULL指针,因为无法 ... -
如果在扫描阵列期间从未设置过mini ,则minimum函数可能会返回未初始化的值。 我不确定你的逻辑应该是什么,但也许你应该在你的函数顶部初始化mini = 0或做其他事情以防止这种情况发生。 您没有指定给定矩阵中应该包含的内容,但作为示例,所有零的矩阵将触发此行为。 Your function minimum could possibly return an uninitialized value, if mini was never set during your scan of the array. ...
-
分段故障(Segmentation fault)[2022-04-03]
使用new而不是malloc在堆上创建C ++对象。 下列: head = (PNODE) malloc(sizeof(NODE)); 应该读 head = new NODE; malloc()在这里不起作用的原因是它不调用对象构造函数。 Use new rather than malloc to create C++ objects on the heap. The following: head = (PNODE) malloc(sizeof(NODE)); should read head = ... -
你必须传递指向fscanf值而不是值的指针(注意& temp- &temp->id和&temp->gpa的&符号; char[] -types lname和fname自动衰减为指针): while(fscanf(file1, "%s %s %d %f", temp->fname, temp->lname, &temp->id, &temp->gpa) != EOF) { You have to pass pointers to values instead of values to fscanf (not ...
-
嗯,你确定段错是来自那个代码吗? 你调试过了吗? 我宁愿尝试这个: int sum_to_leaf(struct node* root,int sum) { if(root==NULL) { return sum; } else { sum=sum+root->data; int left_sum = sum_to_leaf(root->left, sum); int right_sum = sum_to_leaf(r ...
-
基于指针的代码在CodeBlocks中给出Segmentation fault(Pointers based code giving Segmentation fault in CodeBlocks)[2022-08-28]
当check_board 应该是一个struct数组时,它被声明为一个指针数组。 同样对于dummy和dummy_symbol ( dummy_symbol ,你根本不需要)。 如果你想要malloc一个符号,那么malloc一个符号,而不是一个符号的指针。 但你甚至不需要malloc :只需声明基于堆栈的变量: struct Player_symbols player_1_symbols; // no pointer, no malloc needed Your check_board is decla ... -
根据问题陈述, T可能高达100000.当T高于100时,以下语句 scanf("%d %d",&n[i],&m[i]); 产生未定义的行为,因为n和m都是100。 由于每个测试用例都可以单独处理,所以根本不需要n和m数组:用标量变量m和n替换它们,删除第一个for循环,并在第二个循环中调用scanf : int i,t,flag,j,x,k,m,n; scanf("%d",&t); for(x=1;x<=t;x++) { scanf("%d %d", &n, &m); ... } 注意 ...