在Lua 5.3.0,我运行" true and print("Hi")":
> true and print("Hi")
Hi
nil
Run Code Online (Sandbox Code Playgroud)
为什么程序输出nil?
在将数组<>项分配给临时变量后更改其值时,主变量值也会更改.
Array<Cards> cards = new Array<Cards>();
//add items to cards
Iterator<Cards> iterator = cards.iterator();
while(iterator.hasNext()){
Cards c = iterator.next();
Cards Temp = c;
//when I change values of temp...the value of c also changes
//overall changing the value of cards
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以改变Temp的价值而不是c或卡吗?
我目前正在用libgdx为Android制作游戏.
我遇到了分段错误,我不知道问题出在哪里.
#include "stdio.h"
#include "stdlib.h"
struct node {
int data;
struct node *next;
};
struct node *head = NULL;
struct node * curr;
struct node * newNode;
void createList(){
int data,n , i ;
scanf("%d",&n);
for (i = 0 ; i < n ;i++){
scanf("%d",&data);
curr = head;
newNode = (struct node*)malloc(sizeof(struct node));
newNode->data=data;
newNode->next=NULL;
if ( curr == NULL){
head = newNode;
}else
while (curr->next != NULL){
curr = curr->next;
}
curr->next = newNode;
}
}
int main(int argc, …Run Code Online (Sandbox Code Playgroud) 考虑一下案例:
char s1[] = "abc";
s1[3] = 'x';
printf("%s", s1);
Run Code Online (Sandbox Code Playgroud)
据我所知,printf打印字符直到找到空字符然后停止.
当我覆盖空字符时'x',为什么要正确printf打印s1数组?它是如何找到空字符的?
在C中,double比float更精确,根据"C primerplus第六版"一书(第80页),浮点数可以代表至少6位有效数字,而double可以代表至少13位有效数字.所以我尝试用这个简单的例子验证:
#include<stdio.h>
int main(void){
float a = 3.3333333; // 7 significant digits
double b = 3.33333333333333;// 14 significant digits
printf("\nFloat: %f\n", a);
printf("Double: %f\n", b);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是该计划的输出:
Float : 3.333333
Double: 3.333333
Run Code Online (Sandbox Code Playgroud)
为什么double值与float值具有相同的精度,而不是显示更多有效数字?