Use of diff pointers

Discussion in 'C Programming' started by Comp.Lang.c, May 20, 2006.

  1. Comp.Lang.c

    Comp.Lang.c Guest

    Hello
    Iam Niranjan... i have one small doubt.

    void main()
    {
    int size;
    size = sizeof(int *);
    printf("\n size of int *------>%x"size);
    size = sizeof(char *);
    printf("\n size of char *------>%x"size);
    size = sizeof(float *);
    printf("\n size of float *------>%x"size);
    }
    here i got the same size for all three.
    when all three taking the same size... why we need different type of
    pointers..
    plz clarify any one..
    Thanking you
    Niranjan
     
    Comp.Lang.c, May 20, 2006
    #1
    1. Advertising

  2. Comp.Lang.c said:

    > Hello
    > Iam Niranjan... i have one small doubt.
    >
    > void main()


    Lesson 1: main returns int, not void.

    When you have absorbed that lesson, let us know.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, May 20, 2006
    #2
    1. Advertising

  3. Comp.Lang.c

    Comp.Lang.c Guest

    whats the relation between main return type & pointers size...?
     
    Comp.Lang.c, May 20, 2006
    #3
  4. Comp.Lang.c said:

    > whats the relation between main return type & pointers size...?


    None whatsoever, because main always returns int.

    When you understand that, we can move on to the next error in your example
    program. There doesn't seem to be any point in teaching you new things
    until you've understood the old things correctly. It would be like building
    a house on sand.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, May 20, 2006
    #4
  5. "Comp.Lang.c" <> writes:
    > Iam Niranjan... i have one small doubt.


    I suggest you pick a name for yourself other than "Comp.Lang.c".
    That's the name of the newsgroup; referring to yourself by the same
    name is bound to cause confusion. (Using your own real name is
    usually best, but some people choose to use pseudonyms.)

    > void main()


    int main(void)

    > {
    > int size;
    > size = sizeof(int *);
    > printf("\n size of int *------>%x"size);
    > size = sizeof(char *);
    > printf("\n size of char *------>%x"size);
    > size = sizeof(float *);
    > printf("\n size of float *------>%x"size);
    > }
    > here i got the same size for all three.
    > when all three taking the same size... why we need different type of
    > pointers..


    Because they point to different types.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, May 20, 2006
    #5
  6. Comp.Lang.c

    Typhonike Guest

    they have fixed in size because pointer do not hold the variable's
    itself they only hold the adresses.But it do not mean that one type of
    pointer can hold all the types.we have to tell the compiler "this
    pointer is use for this type of variable".the reason is c uses STRONGLY
    TYPE CHECKING.we can't change variables types(of course pointers are
    variavles too) during the run time and compile time.
     
    Typhonike, May 20, 2006
    #6
  7. Comp.Lang.c

    Comp.Lang.c Guest

    Thanq Mr Keith Thompson.
    its very very nice meeting you.
    Thanking you, for your great Help.
    Niranjan Podduturi.
    +919849238297
     
    Comp.Lang.c, May 20, 2006
    #7
  8. Comp.Lang.c

    Comp.Lang.c Guest

    Hello Sir,
    I know ...
    void main returns int.
    Iam niranjan podduturi.
    Iam from Hyderabad/India
    Thanking you Sir.
    Niranjan Podduturi
     
    Comp.Lang.c, May 20, 2006
    #8
  9. Comp.Lang.c said:

    > Hello Sir,
    > I know ...
    > void main returns int.


    No, main returns int.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, May 20, 2006
    #9
  10. Comp.Lang.c

    pete Guest

    Typhonike wrote:
    >
    > they have fixed in size because pointer do not hold the variable's
    > itself they only hold the adresses.


    No.

    sizeof(int *), sizeof(char *), and sizeof(float *)
    are all equal on OP's implementation through sheer coincidence.

    The relative sizes of those types of pointers
    is unspecified by the rules of the C programming language.

    --
    pete
     
    pete, May 20, 2006
    #10
  11. On 19 May 2006 23:25:50 -0700, "Comp.Lang.c"
    <> wrote:

    >Hello
    >Iam Niranjan... i have one small doubt.
    >
    >void main()
    >{
    >int size;
    >size = sizeof(int *);
    >printf("\n size of int *------>%x"size);
    >size = sizeof(char *);
    >printf("\n size of char *------>%x"size);
    >size = sizeof(float *);
    >printf("\n size of float *------>%x"size);
    >}
    >here i got the same size for all three.
    >when all three taking the same size... why we need different type of
    >pointers..
    >plz clarify any one..
    >Thanking you
    >Niranjan


    Try the following:

    #include <stdio.h>
    #include <stdlib.h>

    int main()
    {
    int size;
    int *p_to_int;
    char *p_to_char;
    short *p_to_short;
    float *p_to_float;

    size = sizeof(int *);
    printf("size of int * ------->%x\n", size);

    size = sizeof(char *);
    printf("size of char * ------->%x\n", size);

    size = sizeof(short *);
    printf("size of short * ------>%x\n", size);

    size = sizeof(float *);
    printf("size of float * ------>%x\n", size);

    size = sizeof(*p_to_int);
    printf("size of *p_to_int ------>%x\n", size);

    size = sizeof(*p_to_char);
    printf("size of *p_to_char ------>%x\n", size);

    size = sizeof(*p_to_short);
    printf("size of *p_to_short ------>%x\n", size);

    size = sizeof(*p_to_float);
    printf("size of *p_to_float ------>%x\n", size);

    return EXIT_SUCCESS;
    }
     
    Roberto Waltman, May 20, 2006
    #11
  12. Roberto Waltman <> wrote:
    ><> wrote:
    >>here i got the same size for all three.
    >>when all three taking the same size... why we need different type of
    >>pointers..
    >>plz clarify any one..
    >>Thanking you
    >>Niranjan

    >
    >Try the following:


    Sorry, pasted the wrong file. I meant, try the following:

    #include <stdio.h>
    #include <stdlib.h>

    int main()
    {
    int size;
    char *p_to_char;
    short *p_to_short;
    int *p_to_int;
    float *p_to_float;
    double *p_to_double;

    size = sizeof(p_to_char);
    printf("size of p_to_char ------>%x\n", size);

    size = sizeof(*p_to_char);
    printf("size of *p_to_char ------>%x\n", size);

    size = sizeof(p_to_short);
    printf("size of p_to_short ------>%x\n", size);

    size = sizeof(*p_to_short);
    printf("size of *p_to_short ------>%x\n", size);

    size = sizeof(p_to_int);
    printf("size of p_to_int ------>%x\n", size);

    size = sizeof(*p_to_int);
    printf("size of *p_to_int ------>%x\n", size);

    size = sizeof(p_to_float);
    printf("size of p_to_float ------>%x\n", size);

    size = sizeof(*p_to_float);
    printf("size of *p_to_float ------>%x\n", size);

    size = sizeof(p_to_double);
    printf("size of p_to_double ------>%x\n", size);

    size = sizeof(*p_to_double);
    printf("size of *p_to_double ------>%x\n", size);

    return EXIT_SUCCESS;
    }
     
    Roberto Waltman, May 20, 2006
    #12
  13. Comp.Lang.c

    santosh Guest

    Comp.Lang.c wrote:
    > Hello Sir,
    > I know ...
    > void main returns int.
    > Iam niranjan podduturi.
    > Iam from Hyderabad/India
    > Thanking you Sir.
    > Niranjan Podduturi


    I suppose you're another one of the frustrated BPO f**kers, trying to
    troll on Usenet defaming your own country.

    Go get a life. All you're managing to do is to appear a complete
    jackass.
     
    santosh, May 20, 2006
    #13
  14. Comp.Lang.c

    santosh Guest

    Typhonike wrote:
    > they have fixed in size because pointer do not hold the variable's
    > itself they only hold the adresses.


    <OT>
    Address sizes aren't fixed on all hardware. For example varying pointer
    types were used under the real-mode x86 CPU, because of it's
    segment:eek:ffset nature of memory addressing. The pointer sizes are the
    same for the OP only because of his implementation. Though the OP
    didn't mention it, it's very likely that his platform is a 32-bit x86
    running under a protected mode OS with a 32-bit flat memory model. In
    this case a single GP register can access the full range of a program's
    address space and hence the C pointer types are constant in size.

    The C standard does not specify the particular size or structure of
    pointers. It's upto the implementor, who is in turn, dictated by the
    nature of the hardware.
    </OT>
     
    santosh, May 20, 2006
    #14
  15. Comp.Lang.c

    Default User Guest

    Comp.Lang.c wrote:

    > Hello Sir,
    > I know ...
    > void main returns int.


    Please read the information below.



    Brian

    --
    Please quote enough of the previous message for context. To do so from
    Google, click "show options" and use the Reply shown in the expanded
    header.
     
    Default User, May 20, 2006
    #15
  16. Comp.Lang.c

    santosh Guest

    Comp.Lang.c wrote:
    > Hello Sir,
    > I know ...


    Quote context if you're serious about participating in this newsgroup.
    Read the following:

    <http://cfaj.freeshell.org/google/>
    <http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
    <http://www.safalra.com/special/googlegroupsreply/>
    <http://en.wikipedia.org/wiki/USENET>

    > void main returns int.


    Under a conforming implementation main() returns an int and only an int
    at all times. void main() is invalid.

    > Iam niranjan podduturi.
    > Iam from Hyderabad/India


    Who the hell cares what you're name is or where you stay. Confine your
    posts to this group to ISO C.

    > Thanking you Sir.
    > Niranjan Podduturi


    BTW, Usenet posts aren't letters.
     
    santosh, May 20, 2006
    #16
  17. "santosh" <> writes:
    > Comp.Lang.c wrote:
    >> Hello Sir,
    >> I know ...

    >
    > Quote context if you're serious about participating in this newsgroup.
    > Read the following:
    >
    > <http://cfaj.freeshell.org/google/>
    > <http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
    > <http://www.safalra.com/special/googlegroupsreply/>
    > <http://en.wikipedia.org/wiki/USENET>
    >
    >> void main returns int.

    >
    > Under a conforming implementation main() returns an int and only an int
    > at all times. void main() is invalid.


    That's not *quite* true. The standard allows an implementation to
    define other forms for main(), but only
    int main(void)
    and
    int main(int argc, char **argv)
    are guaranteed to be portable (for hosted implementations), and
    there's practically never a good reason to use void main().

    >> Iam niranjan podduturi.
    >> Iam from Hyderabad/India

    >
    > Who the hell cares what you're name is or where you stay. Confine your
    > posts to this group to ISO C.


    Perhaps you could have expressed this with a bit more subtlety. The
    OP needs to learn a few things about this newsgroup, and about Usenet
    in general, but there's no need to be rude about it.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, May 20, 2006
    #17
  18. Comp.Lang.c

    Tomás Guest

    Keith Thompson posted:

    > That's not *quite* true. The standard allows an implementation to
    > define other forms for main(), but only
    > int main(void)



    We're getting into semantics here, but I don't consider:

    int main()

    to be different from:

    int main(void)


    Nor do I consider any of the following to be different:

    signed main();
    signed int main(void);
    int main();
    signed main(void);
    signed int main();
    int main(void);


    -Tomás
     
    Tomás, May 21, 2006
    #18
  19. "Tomás" <No.Email@Address> writes:
    > Keith Thompson posted:
    >
    >> That's not *quite* true. The standard allows an implementation to
    >> define other forms for main(), but only
    >> int main(void)

    >
    >
    > We're getting into semantics here, but I don't consider:
    >
    > int main()
    >
    > to be different from:
    >
    > int main(void)


    They're different in a declaration (prototype), but the same in a
    definition. But then, there's not much point in declaring a separate
    prototype for main.

    > Nor do I consider any of the following to be different:
    >
    > signed main();
    > signed int main(void);
    > int main();
    > signed main(void);
    > signed int main();
    > int main(void);


    Right. I should have added the phrase "or equivalent". For example:

    typedef int FOOBAR;
    typedef char OCELOT;
    FOOBAR main(FOOBAR lutefisk, OCELOT **uffda);

    is also legal.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
     
    Keith Thompson, May 21, 2006
    #19
  20. In article <b%Obg.9386$> "Tomás" <No.Email@Address> writes:
    ....
    > We're getting into semantics here, but I don't consider:
    > int main()
    > to be different from:
    > int main(void)


    Eh? See the difference when I write
    a = main(1, 2);
    this is valid for "int main()" but not for "int main(void)".
    --
    dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
    home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
     
    Dik T. Winter, May 21, 2006
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cyril Vi?ville

    diff Process under diff users

    Cyril Vi?ville, Jun 29, 2004, in forum: Perl
    Replies:
    1
    Views:
    514
    Joe Smith
    Jun 29, 2004
  2. Berrucho
    Replies:
    2
    Views:
    644
    Infant Newbie
    Dec 5, 2003
  3. A Traveler

    Diff CSS styles for diff INPUT TYPE='s?

    A Traveler, Aug 31, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,932
    Steve Fulton
    Aug 31, 2004
  4. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    683
  5. Austin Ziegler

    [ANN] Diff::LCS 1.1.0, Diff::LCS 1.0.4

    Austin Ziegler, Aug 8, 2004, in forum: Ruby
    Replies:
    3
    Views:
    197
    Austin Ziegler
    Aug 9, 2004
Loading...

Share This Page