Thread: i cant understand something in pointers

  1. #1
    Registered User
    Join Date
    Feb 2010

    i cant understand something in pointers

    #include <stdio.h>
    int main(void){
        int *a,*b;
        int c=10;
        a = &c;
        return 0;
    it prints 51, why? what exactly is this number? it's the memory address of what?


  2. #2
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    It is printing the address that the variable b is located at. If you wanted to print what variable b actually was, your printf statement should appear as follows:
    Also note that you have not even initialized b.

    Also you are passing an (int *) to printf when it is expecting an int. You should be ok because I'm guessing that the machine you are using they are both the same size, but passing unexpected arguments can often result in undefined behavior.
    Last edited by carrotcake1029; 02-12-2010 at 12:20 PM.

  3. #3
    Registered User
    Join Date
    Feb 2010
    thanks a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. Replies: 4
    Last Post: 12-10-2006, 06:08 PM
  3. Request for comments
    By Prelude in forum A Brief History of
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 12:18 PM
Website Security Test