Thread: why i getting different outputs?

  1. #1
    Join Date
    Oct 2009

    why i getting different outputs?

    Hi any one can explain me ,why i getting these outputs?

    struct s
    int data;
    struct s s1; 
    int main()
    printf("%u \n",s1);
    printf("%u \n",&s1);
    return 0;
    i thinking s1 return also address .but both outputs are not same.

    please give explanation on above outputs

  2. #2
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    in front of my computer
    s1 is a not an address. It's a variable of type "struct s". &s is an address.
    Note: To print addresses use %p. eg.
    int i=9;
    printf("%p",(void *)&i);

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior

    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    Quote Originally Posted by nkrao123@gmail. View Post
    please give explanation on above outputs
    Why don't you say what the output was, and what you were expecting?

    The first one probably gives you the value of, altho that is not the proper way to ask for it. is uninitialized, so it may be anything (I think in this case the compiler may set it to zero).

    The second one is the address of s1, altho addresses are usually understood as hexidecimal values, as BEN10 indicates.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 03-05-2009, 11:32 AM
  2. Mouse function outputs?
    By cwn11 in forum C Programming
    Replies: 5
    Last Post: 11-25-2008, 07:01 PM
  3. Replies: 8
    Last Post: 09-11-2006, 11:26 AM
  4. assigning rand outputs to variables
    By 2fastwrx in forum C++ Programming
    Replies: 8
    Last Post: 09-27-2004, 10:17 PM
  5. Outputs
    By kas2002 in forum C++ Programming
    Replies: 3
    Last Post: 10-29-2002, 07:12 PM