Results 1 to 9 of 9

Thread: What's wrong with this?

  1. #1

    Thread Starter
    Hyperactive Member zer0_flaw's Avatar
    Join Date
    Apr 2001
    Posts
    448

    What's wrong with this?

    This is C source code... not c++

    #include <stdio.h>

    int x;
    int *xpos;

    x = 13;
    xpos = &x;

    printf("%i\n",x);
    printf("%p\n\n",xpos);

  2. #2
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    um what are i and n and why do you need a pointer
    Magiaus

    If I helped give me some points.

  3. #3

    Thread Starter
    Hyperactive Member zer0_flaw's Avatar
    Join Date
    Apr 2001
    Posts
    448
    I need a pointer because I am learning C and want to learn how to use them. I want to declare a variable... make a pointer variable point to it, and then print the original variable and the memory location of that variable... aka the pointer.

  4. #4
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    here run this

    don't use stdio.h usiostream just because i say so and i don't like stdio

    Code:
    #include <iostream.h>
    
    int main(){
    	int i = 27;
    	int *pi = &i;
    
    	cout<<"i="<<i<<"\n";
    	cout<<"&pi="<<&pi<<"\n";
    	return 0;
    }
    Magiaus

    If I helped give me some points.

  5. #5
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    He specifically said C, so <iostream.h> is out. Even with C++, it is recommended that you use <iostream>, the newer header file.

    Anyway, try changing the %p to a %i. It should print out the decimal value of the pointer.

    Z.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Magiaus: the %i means print an integer, the \n is a newline.

    zer0_flaw: Do you have a main function in your app?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    yhanks bee man i new what the newline escape char was after i looked at his code closer i just wasn't familer with the 96i

    plus i don't know straight c so.... i guess i shouldn't answer questions unless i know what i'm talking about
    Magiaus

    If I helped give me some points.

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    My bad side just won my internal discussion whether I should post to state that I won't comment on that or not.

    Whatever...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    ater debating i decided to post and say cornedbee is the man
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width