Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 109,726 C++ Programmers for FREE! Ask your question and get quick answers from experts. There are 1,861 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



C syntax clarification

 
Reply to this topicStart new topic

C syntax clarification

raedbenz
post 20 Jul, 2008 - 11:18 AM
Post #1


New D.I.C Head

*
Joined: 13 Dec, 2006
Posts: 19


My Contributions


HI,,,
what are the meaning of the following in C?

Q1.
CODE
int **p;

is it a pointer points to pointer?

Q2.
CODE
int *p;
char **r;
p=(int *)(*r+0x01);

is it casting of pointer or what?

Q3.
CODE
x->y


thanks

This post has been edited by raedbenz: 20 Jul, 2008 - 11:18 AM
User is offlineProfile CardPM

Go to the top of the page


NickDMax
post 20 Jul, 2008 - 11:32 AM
Post #2


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,756



Thanked 34 times

Dream Kudos: 525
My Contributions


Q1: Yes, that is a pointer that points to a pointer. This is called "double indirection" (since a pointer offers single indirection -- though nobody ever seems to call it that).

Q2: p is a pointer to an int, and r is a pointer to a pointer to a char.

So (*r + 0x01) is moving the pointer *r up one character address (presumably 1 byte, but this depends upon the platform you are on).

So p=(int *)(*r+0x01); is casting this pointer into a pointer to an integer and assigning it to p.

Q3: This is a dereference into a structure. In this case x is a pointer to some structure that has an element named "y".

CODE

#include <stdio.h>

struct foobar {
    int a;
    int b;
};

void funct(struct foobar* ptr) {
    ptr->a = 0;
    ptr->b = 1;
}

int main() {
    struct foobar foo;
    funct(&foo);
    printf("foo.a = %d, foo.b = %d\n", foo.a, foo.b);
    system("pause");    
}


basically it means the same as: (*x).y just easier to type.
User is offlineProfile CardPM

Go to the top of the page

raedbenz
post 28 Jul, 2008 - 07:51 AM
Post #3


New D.I.C Head

*
Joined: 13 Dec, 2006
Posts: 19


My Contributions


Thanks very much,,,,
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 9/8/08 09:56AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month