what does this function mean?

Hi everyone,
I have this function I did not understand it and I don't get the condition in the if statement. If you can please explain this function.

Thank you in advance.

1
2
3
4
5
6
7
8
bool DateAndTime::leapYear()
{
	
	if(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
	return true;
	else
		return false;
}
if(year % 400 == 0 If year is divisible by 400 it is leap year
|| OR
(year % 4 == 0 && year % 100 != 0)) if year is divisible by 4 AND(&&) NOT(!) divisible by 100 year is leap year.
I thank you eraggo so much for your explanation. it helps a lot.
The function can be rewritten much simpler

1
2
3
4
5
bool DateAndTime::leapYear()
{
	
	return ( ( year % 400 == 0 ) || ( year % 4 == 0 && year % 100 != 0 ) );
}
Topic archived. No new replies allowed.