It's UWAweek 47

help2002

This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.
Displaying selected article
Showing 1 of 828 articles.
Currently 76 other people reading this forum.


 UWA week 35 (2nd semester, week 6) ↓
SVG not supported

Login to reply

👍?
helpful

This isn't a question but just something I find useful and hopefully others might also find useful, to get my head around the different uses of the * operator in pointer syntax.

While it seems like the expression *p can take on a few different meanings depending on context, it can pretty consistently be read as "the value of p". I'll illustrate with some examples (compared against regular/non-pointer equivalents):

int x;  // define x to be an int
int *p; // define the value of p to be an int

x = 5;  // set x to 5
*p = 5; // set the value of p to 5

int y;
y = x;  // set y to x
y = *p; // set y to the value of p

It even works for functions, kinda:

int foo()  // the thing foo returns will be an int
{
    ...
}

int *foo() // the value of the thing foo returns will be an int
{
    ...
}

It's not perfect obviously, but it's maybe a useful fallback and preferable to trying to remember how each of the contexts work independently.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  8:08AM Aug 25 2024
Privacy policy