C Reference Cheat Sheet Page 12

ADVERTISEMENT

C Reference Cheat Sheet
by
Ashlyn Black
via
The Time Library
Unary Operators (cont)
Returns a then decrements a by 1. (a = a - 1)
#include <time.h>
a--
Variable Types
Typecasts a as type.
(type)a
Stores the calendar time.
Memory location of a.
time_t
&a;
Stores a time & date breakdown.
Memory size of a (or type) in bytes.
struct tm *x;
sizeof(a)
tm structure members:
Binary Operators
Seconds, 0 to 59.
int tm_sec
by descending evaluation preced ​ e nce
Minutes, 0 to 59.
int tm_min
Product of a and b. (a × b)
a * b;
Hours, 0 to 23.
int tm_hour
Quotient of dividend a and divisor b. Ensure divisor is non-
a / b;
Day of the month, 1 to 31.
int tm_mday
zero. (a ÷ b)
Month, 0 to 11.
int tm_mon
Remainder of integers dividend a and divisor b.
a % b;
Years since 1900.
int tm_year
Sum of a and b.
a + b;
Day of the week, 0 to 6.
int tm_wday
Difference of a and b.
a - b;
Day of the year, 0 to 365.
int tm_yday
b
Left bitwise shift of a by b places. (a × 2 )
a << b;
Daylight saving time.
int tm_isdst
-b
Right bitwise shift of a by b places. (a × 2 )
a >> b;
Functions
Less than. True if a is less than b and false otherwise.
a < b;
Returns unix epoch time (seconds since
time(NULL)
Less than or equal to. True if a is less than or equal to b and
a <= b;
1/Jan/1970.)
false otherwise. (a ≤ b)
Stores the current time in a time_t
time(&time_t);
Greater than. True if a is greater than than b and false
a > b;
variable.
otherwise.
Returns a time_t variable as a string.
ctime(&time_t)
Greater than or equal to. True if a is greater than or equal to
a >= b;
Breaks time_t down into struct tm
x = localtime(
b and false otherwise. (a ≥ b)
members.
&time_t);
Equality. True if a is equal to b and false otherwise. (a ⇔ b)
a == b;
Inequality. True if a is not equal to b and false otherwise. (a ≠
Unary Operators
a != b;
b)
by descending evaluation preced ​ e nce
Bitwise AND of a and b. (a ⋂ b)
a & b;
Sum of 0 (zero) and a. (0 + a)
+a
Bitwise exclusive-OR of a and b. (a ⊕ b)
a ^ b;
Difference of 0 (zero) and a. (0 - a)
-a
Complement (logical NOT) of a. (~a)
!a
Binary ones complement (bitwise NOT) of a. (~a)
~a
Increment of a by 1. (a = a + 1)
++a
Decrement of a by 1. (a = a - 1)
--a
Returns a then increments a by 1. (a = a + 1)
a++
By Ashlyn Black
Published 28th January, 2015.
Sponsored by
Last updated 20th April, 2015.
Measure your website readability!
Page 12 of 13.

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education