![]() |
| | #1 |
| Registered User Join Date: Oct 2009
Posts: 10
| Pointer Assignment The question states: Assume the declaration Code: int m = 35, *intPtr; double x, *dblPtr; a) Assign intPtr a value so it points to m b) Assign dblPtr a value so it points to x, amd then use the pointer to assign x the value of 5.3 On (a), I think it is: Code: intPtr = &m; Code: dblPtr = &x; *dblPtr = 5.3; I think I am right on the first set. Can someone please let me know? Thanks |
| cardinals03 is offline | |
| | #2 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,263
| What you have now is correct. Still, you could change it to what you were considering, compile, and observe what you get.
__________________ 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 | |
| | #3 |
| Registered User Join Date: Jan 2005
Posts: 7,246
| Your code looks right as is. Look at the two statements for dblPtr. One assigns an address, the other assigns a value. The pointer itself holds an address, which is why you assign directly to dblPtr. But the value should be assigned to the dereferenced pointer, which is why you added the * for the second one. |
| Daved is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Following CTools | EstateMatt | C Programming | 5 | 06-26-2008 10:10 AM |
| Screwy Linker Error - VC2005 | Tonto | C++ Programming | 5 | 06-19-2007 02:39 PM |
| Quick question about SIGSEGV | Cikotic | C Programming | 30 | 07-01-2004 07:48 PM |
| assignment discards qualifiers from pointer target type | Nyda | C Programming | 3 | 06-19-2004 10:24 AM |
| assignment makes pointer from integer | crescen7 | C Programming | 4 | 06-25-2002 10:08 PM |