理解别人代码的时候有两行看不太懂什么意思
own_chunk_size = (number_of_elements >= chunk_size*(rank_of_process + 1)) ? chunk_size : (number_of_elements - chunk_size*rank_of_process);和
int received_chunk_size= (number_of_elements>= chunk_size* (rank_of_process + 2 * step))? (chunk_size * step): (number_of_elements- chunk_size* (rank_of_process + step));
有没有大佬能帮忙简化成 if else 的形式
主要就是不明白 '?' 和 ':' 在这里面起到的作用,谢谢! //own_chunk_size = (number_of_elements >= chunk_size*(rank_of_process + 1)) ? chunk_size : (number_of_elements - chunk_size*rank_of_process);
if(number_of_elements >= chunk_size*(rank_of_process + 1))
{
own_chunk_size = chunk_size;
}
else
{
own_chunk_size = number_of_elements - chunk_size*rank_of_process;
}
//int received_chunk_size= (number_of_elements>= chunk_size* (rank_of_process + 2 * step))? (chunk_size * step): (number_of_elements- chunk_size* (rank_of_process + step));
int received_chunk_size;
if(number_of_elements>= chunk_size* (rank_of_process + 2 * step))
{
received_chunk_size = chunk_size * step;
}
else
{
received_chunk_size = number_of_elements- chunk_size* (rank_of_process + step);
}
就是三元运算符,原理是:
res = (条件判断语句) ? a : b
等价于
if(条件判断语句):
res = a
else:
res = b
第二个
int received_chunk_size = 0
if number_of_elements >= chunk_size * (rank_of_process + 2 * step):
received_chunk_size = chunk_size * step
else:
received_chunk_size = number_of_elements - chunk_size * (rank_of_process + step)
昨晚熬夜到四点吗{:10_261:} 人造人 发表于 2021-9-28 07:29
谢谢大佬,刚起,吃完饭研究研究{:10_266:} 小甲鱼的铁粉 发表于 2021-9-28 07:30
就是三元运算符,原理是:
等价于
谢谢大佬,刚起,吃完饭研究研究.确实,熬夜到了 4 点,躺床上也睡不着,玩了会儿手机,估计 6 点才睡的吧,太难了{:10_266:} Daniel_Zhang 发表于 2021-9-28 14:00
谢谢大佬,刚起,吃完饭研究研究.确实,熬夜到了 4 点,躺床上也睡不着,玩了会儿手机,估计 6 点才睡的吧,太难 ...
我以为我熬的够久了
没想到。。。。。{:10_250:}
这是谁的部将 人造人 发表于 2021-9-28 07:29
谢谢大佬再次救我狗命!{:10_250:}
页:
[1]