LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-08-2005, 05:43 PM   #1
AM1SHFURN1TURE
Member
 
Registered: Sep 2004
Location: US
Distribution: Debian
Posts: 56

Rep: Reputation: 15
globs in C pointers


I have notcied globs used in pointer names both at the start and the beginning of the name.
(ex. *pointer and pointer * )
What is the difference? I haven't found an explanation.
 
Old 07-08-2005, 06:03 PM   #2
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
The symbol in front of the pointer is used for "dereferencing" a pointer. That is, accessing the memory that the pointer points to. As an example:

Code:
int i = 10;
// Create a pointer p that points to the memory 
// address of i
int* p = &i;

// Print out the dereferenced value that p points to, 
// this will output 10
printf("%d\n", *p);

// Dereferece p and set the value to 5.  This is 
//accessing the memory of i, so i will be 5 after this
*p = 5;
printf("%d\n", i);
Not quite sure what you mean by the pointer * format. Perhaps you could give a specific example. The only thing I can think of off the top of my head is something like:

int* p;

vs.

int *p;

Both of the above are equivalent.
 
Old 07-08-2005, 06:07 PM   #3
AM1SHFURN1TURE
Member
 
Registered: Sep 2004
Location: US
Distribution: Debian
Posts: 56

Original Poster
Rep: Reputation: 15
ahh there we go, I was being confused by some stuff I was reading, it kept switching between things like 'int* x' and 'int *x' without giving an explanation of it, thanks - you 'deconfused' me
 
Old 07-09-2005, 05:30 PM   #4
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
It's confusing to write int* p; since the * binds to p, not to int. Consider:
Code:
int* p, q;
int *p, q;
int *p, *q;
q in the second line is an int not a pointer to int.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers in c++ marios_auth Programming 1 06-16-2004 08:20 AM
Pointers Pointers Pointers urzumph Programming 9 03-11-2004 09:49 AM
Looking for some pointers... p3ngu!n Linux - Newbie 17 10-30-2003 06:46 AM
pointers in C again h/w Programming 9 10-29-2003 11:46 PM
need help with pointers qanopus Programming 8 02-03-2003 05:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration