Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #158689
| From | John Bode <jfbode1029@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: what is a & ? |
| Date | 2021-01-28 11:02 -0600 |
| Organization | A noiseless patient Spider |
| Message-ID | <d480cc65-e99d-45d8-cdbc-170a8dcc686c@gmail.com> (permalink) |
| References | <rs6ar2$7nj$1@dont-email.me> |
Very late to this party, as usual.
On 12/25/20 9:31 PM, T wrote:
> Hi All,
>
> I the following code, I do beleive I hae everything
> figured out, except for "&rawtime". It looks like it
> is a time_t (long long integer or 64 bit integer).
> What does the "&" do to the variable?
>
The unary '&' operator is the address-of operator - the result
of '&rawtime' is the address of the 'rawtime' variable.
IOW, '&rawtime' is a pointer expression, and the type of the
expression is 'time_t *' (pointer to 'time_t').
The 'time()' function expects a 'time_t *' (pointer to 'time_t')
value as its argument. In this case it's because 'time()'
needs to write a new value to 'rawtime' and C functions can only
update parameters through pointers.
'localtime()' also expects a time_t *' argument, although
it doesn't actually modify the parameter. Sometimes pointers
are used to hide platform-dependent specifics, sometimes
they're used to minimize the amount of data that has to be
passed directly to the function (minimize stack space or
register usage), etc.
'time_t' is a real (scalar) type that can represent time values;
its exact representation is implementation-dependent. It *may*
be a 64-bit integer, or it may be something else.
>
> https://www.cplusplus.com/reference/ctime/localtime/
>
> /* localtime example */
> #include <stdio.h> /* puts, printf */
> #include <time.h> /* time_t, struct tm, time, localtime */
>
> int main ()
> {
> time_t rawtime;
> struct tm * timeinfo;
>
> time (&rawtime);
> timeinfo = localtime (&rawtime);
> printf ("Current local time and date: %s", asctime(timeinfo));
>
> return 0;
> }
>
>
>
> Many thanks,
> -T
Back to comp.lang.c | Previous | Next — Previous in thread | Find similar | Unroll thread
what is a & ? T <T@invalid.invalid> - 2020-12-25 19:31 -0800
Re: what is a & ? fir <profesor.fir@gmail.com> - 2020-12-25 21:11 -0800
Re: what is a & ? T <T@invalid.invalid> - 2020-12-25 21:37 -0800
Re: what is a & ? "wolfgang bauer (D)" <schutz@gmx.de> - 2020-12-26 06:15 +0100
Re: what is a & ? T <T@invalid.invalid> - 2020-12-25 21:37 -0800
Re: what is a & ? scott@slp53.sl.home (Scott Lurndal) - 2020-12-26 16:31 +0000
Re: what is a & ? T <T@invalid.invalid> - 2020-12-26 18:28 -0800
Re: what is a & ? Bart <bc@freeuk.com> - 2020-12-27 12:31 +0000
Re: what is a & ? David Brown <david.brown@hesbynett.no> - 2020-12-27 15:32 +0100
Re: what is a & ? Bart <bc@freeuk.com> - 2020-12-27 14:53 +0000
Re: what is a & ? David Brown <david.brown@hesbynett.no> - 2020-12-27 16:40 +0100
Re: what is a & ? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2020-12-27 12:03 -0800
Re: what is a & ? Bart <bc@freeuk.com> - 2020-12-27 20:33 +0000
Re: what is a & ? T <T@invalid.invalid> - 2020-12-27 17:43 -0800
Re: what is a & ? David Brown <david.brown@hesbynett.no> - 2020-12-28 11:00 +0100
Re: what is a & ? Bart <bc@freeuk.com> - 2020-12-28 11:16 +0000
Re: what is a & ? T <T@invalid.invalid> - 2020-12-27 20:36 -0800
Re: what is a & ? T <T@invalid.invalid> - 2020-12-27 20:48 -0800
Re: what is a & ? Bonita Montero <Bonita.Montero@gmail.com> - 2020-12-27 18:30 +0100
Re: what is a & ? John Bode <jfbode1029@gmail.com> - 2021-01-28 11:02 -0600
csiph-web