Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- ////////////////////////////////////////////////////
- struct Cday
- {
- int nYear;
- const char *pszDay;
- int nSec;
- };
- void foo(Cday d);
- ////////////////////////////////////////////////////
- int main() //
- {
- Cday day1;
- day1.nYear = 2022;
- day1.pszDay = "Monday";
- day1.nSec = 1688169600;
- printf("size Cday = %d\n", sizeof(day1) );
- printf("address day1 = %d\n", &day1);
- foo(day1);
- }
- ////////////////////////////////////////////////
- void foo(Cday d)
- {
- printf("address d = %d\n", &d);
- printf("d.nYear = %d\n", d.nYear );
- printf("d.pszDay = %s\n", d.pszDay);
- printf("d.nSec = %d\n", d.nSec );
- printf(" - - - - - - -\n" );
- printf("d.nYear = %d\n", d );
- // printf("d.pszDay = %s\n", d );
- printf("d.nSec = %d\n", (int)(&d)+8 );
- }
- /// Задачка получилась сложная. Вот моё решение:
- // Если сможете упростить, будет отлично.
- #include <stdio.h>
- ////////////////////////////////////////////////////
- struct Cday
- {
- int nYear;
- const char *pszDay;
- int nSec;
- };
- void foo(Cday d);
- ////////////////////////////////////////////////////
- int main() //
- {
- Cday day1;
- day1.nYear = 2022;
- day1.pszDay = "Monday";
- day1.nSec = 1688169600;
- printf("size Cday = %d\n", sizeof(day1) );
- printf("address day1 = %d\n", &day1);
- foo(day1);
- }
- ////////////////////////////////////////////////
- void foo(Cday d)
- {
- printf("address d = %d\n", &d);
- printf("d.nYear = %d\n", d.nYear );
- printf("d.pszDay = %s\n", d.pszDay);
- printf("d.nSec = %d\n", d.nSec );
- printf(" - - - - - - -\n" );
- printf("d.nYear = %d\n", d );
- // printf("d.pszDay = %s\n", d );
- char *p = (char*)&d;
- p = p + 4;
- printf("d.pszDay address = %d\n", p );
- int *pn = (int*)p;
- char *psz2 = (char*)*pn;
- printf("d.pszDay = %s\n", psz2 );
- p = p + 4;
- printf("d.nSec address = %d\n", p );
- pn = (int*)p; printf("d.nSec = %d\n", *pn );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement