Thread: Variables?

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    6

    Variables?

    So none of my variables were saving so I made this simple code to check to see what was up and I dont know what to do

    Code:
    int main()
    {
    int x,y;
    x=1;
    y=1;
    printf("%d %d", &x, &y);
    }

    Returns

    2280676 2280672
    ----jGRASP cygwin wedge2: exit code for process is 15.
    ----jGRASP: operation complete.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Because & is "the address of". So you're not printing x, you're printing where in memory x lives.

  3. #3
    UnknownAmateur Programmer
    Join Date
    Sep 2008
    Location
    Were definitly not in Kasas anymore...
    Posts
    25
    On my compiler you are not supposed to put the '&' sign infront of the variable so my program would look like this,
    Code:
    main()
    {
        int x;
        int y;
    
        x=1;
        y=1;
    
        printf("%d %d", x, y);
    }
    That is how I would do that.

    C-Compiler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  3. esbo's data sharing example
    By esbo in forum C Programming
    Replies: 49
    Last Post: 01-08-2008, 11:07 PM
  4. Craps Program with Local Variables
    By tigrfire in forum C Programming
    Replies: 12
    Last Post: 11-09-2005, 09:01 AM
  5. Declaring an variable number of variables
    By Decrypt in forum C++ Programming
    Replies: 8
    Last Post: 02-27-2005, 04:46 PM