why i getting different outputs?

This is a discussion on why i getting different outputs? within the C Programming forums, part of the General Programming Boards category; Hi any one can explain me ,why i getting these outputs? Code: #include<stdio.h> struct s { int data; }; struct ...

  1. #1
    kotin
    Join Date
    Oct 2009
    Posts
    132

    why i getting different outputs?

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

    Code:
    #include<stdio.h>
    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
    Location
    in front of my computer
    Posts
    804
    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.
    Code:
    int i=9;
    printf("%p",(void *)&i);
    HOPE YOU UNDERSTAND.......

    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
    Location
    segmentation fault
    Posts
    8,300
    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 s1.data, altho that is not the proper way to ask for it. s1.data 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, 10:32 AM
  2. Mouse function outputs?
    By cwn11 in forum C Programming
    Replies: 5
    Last Post: 11-25-2008, 06: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, 06:12 PM

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