什么是“%”在C中的意思 [英] What does "%" mean in C

查看:149
本文介绍了什么是“%”在C中的意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我是C编程的新手,正在处理一些简单的代码。有时我会遇到如下行:


flag =(i%primes [j]);


在这种情况下,变量''i'','j''和''flag''是整数,''primes''是一个数组。我知道''%''用作printf语句中的能指,例如其中%d表示小数位,但在上面的上下文中是什么意思?

Hi. I am new to C programming and am working through some simple bits of code. Sometimes I come across a line like:

flag = (i%primes[j]);

In this case, the variable ''i'', ''j'' and ''flag'' are integers and ''primes'' is an array. I understand that ''%'' is used as a signifier in printf statements, e.g. where %d indicates a position for a decimal, but what does it mean in the above context?

Thanks

推荐答案


嗨。我是C编程的新手,正在处理一些简单的代码。有时我会遇到如下行:


flag =(i%primes [j]);


在这种情况下,变量''i'','j''和''flag''是整数,''primes''是一个数组。我知道''%''用作printf语句中的能指,例如其中%d表示小数位,但在上面的上下文中是什么意思?

Hi. I am new to C programming and am working through some simple bits of code. Sometimes I come across a line like:

flag = (i%primes[j]);

In this case, the variable ''i'', ''j'' and ''flag'' are integers and ''primes'' is an array. I understand that ''%'' is used as a signifier in printf statements, e.g. where %d indicates a position for a decimal, but what does it mean in the above context?

Thanks



it用于mod运算符。

it is used of mod operator .



它用于mod运算符。
it is used of mod operator .



模运算符返回左侧的剩余部分除以右侧。所以5%2将评估为1.(5/2 = 2余数:1)。

The modulo operator returns the remainder of the left side divided by the right side. So 5%2 will evalutate to 1. (5 / 2 = 2 remainder : 1).



模运算符返回剩下的左侧由右侧分开。因此5%2将评估为1.(5/2 = 2余数:1)。
The modulo operator returns the remainder of the left side divided by the right side. So 5%2 will evalutate to 1. (5 / 2 = 2 remainder : 1).





我只是想添加%运算符只能用于整数。


问候,

Pradeep

Hi,
I just wanted to add % operator can be used only with "integers".

Regards,
Pradeep


这篇关于什么是“%”在C中的意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆