question about pointer?

This is a discussion on question about pointer? within the C Programming forums, part of the General Programming Boards category; can I assign a consistant to a pointer varible? like int *p; *p = 13; ??? or can i use ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    6

    Unhappy question about pointer?

    can I assign a consistant to a pointer varible? like
    int *p;
    *p = 13;
    ???
    or can i use pointer like this:
    int *p;
    int e = 13;
    *p == e;
    thanks for your help!can I assign a consistant to a pointer varible? like

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    A variable holds an address, if you can print out the address of what you want the pointer to point to then you can assign it to a pointer.

    printf ( "%d", &13 );
    would flag an error, so you can't assign a constant to a pointer unless it can be used as an address itself. In that case you would use the syntax
    ptr = 0x08;
    or something similar

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >can I assign a consistant to a pointer varible? like
    >int *p;
    >*p = 13;
    >???
    No, p must point to something first.

    >or can i use pointer like this:
    >int *p;
    >int e = 13;
    >*p == e;

    No, but you can do this:
    int *p;
    int e = 13;
    p = &e; //point p to e

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 05:23 AM
  2. Easy pointer question
    By Edo in forum C++ Programming
    Replies: 3
    Last Post: 01-19-2009, 10:54 AM
  3. char pointer to pointer question
    By Salt Shaker in forum C Programming
    Replies: 3
    Last Post: 01-10-2009, 11:59 AM
  4. Pointer question
    By rakan in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2006, 02:23 AM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM

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