C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-09-2010, 06:25 AM   #1
Registered User
 
Join Date: Feb 2010
Posts: 3
Help

This is the question stated in my home assignment:

A structure pointer times of type time (which has three fields, all pointers to integers, day, month and year respectively) is declared. Using the pointer times, update the field day to 10.

a) times.day=10
b) *(times->day)=10
c) *times.day=10;
d) times.day=*10

I personally think that the answer should be either

times->day =10

or

(*times).day=10.

However both of these are not the given choices......

Last edited by yuyu909; 02-09-2010 at 07:25 AM.
yuyu909 is offline   Reply With Quote
Old 02-09-2010, 06:39 AM   #2
Epy
I like turtles
 
Join Date: Sep 2009
Location: Ohio
Posts: 311
The rule of thumb is that if a struct is declared as a plain struct, you use the ., if it is declared as a pointer, you use the ->. So I'd go with b.
__________________
-Jake
http://thatcadguy.blogspot.com/
Epy is offline   Reply With Quote
Old 02-09-2010, 06:48 AM   #3
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 11,275
Quote:
Originally Posted by yuyu909
I personally think that the answer should be either

times->day =10

or

(*times).day=10.
Me too.

Quote:
Originally Posted by yuyu909
However both of these are the given choices......
As in the only choices are the first four that you listed? Taking the question as-is, it then looks like the none of the given options are correct. You may want to approach your instructor for clarification.
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump


All times are GMT -6. The time now is 02:28 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22