Results 1 to 10 of 10

Thread: sizeof() operator

  1. #1
    Junior Member
    Join Date
    May 2008
    Answers
    8

    Thumbs up sizeof() operator

    give the o/p for the following code ....also explain how...


    int i=10,j;
    j=sizeof(++i + ++i);
    printf("%d %d",i,j);


  2. #2
    Junior Member
    Join Date
    May 2008
    Answers
    2

    Re: sizeof() operator

    Integer size is 2 bytes. so j carring value 2 and i carrying value 12.

    Last edited by Sriroshika; 05-27-2008 at 03:01 AM.

  3. #3
    Junior Member
    Join Date
    May 2008
    Answers
    2

    Re: sizeof() operator

    the result is i=12 and j=2

    Last edited by Sriroshika; 05-27-2008 at 03:03 AM.

  4. #4
    Junior Member
    Join Date
    May 2008
    Answers
    8

    Thumbs up Re: sizeof() operator

    Quote Originally Posted by Sriroshika View Post
    Integer size is 2 bytes. so j carring value 2 and i carrying value 12.
    thanks for the answer...but i carries the same 10 and j carries 2...
    test the code please and let me know y the value of i remains the same..


  5. #5

    Re: sizeof() operator

    Quote Originally Posted by jaiprabuk View Post
    thanks for the answer...but i carries the same 10 and j carries 2...
    test the code please and let me know y the value of i remains the same..
    how i carry the value 12 please give the detial answer


  6. #6
    Junior Member
    Join Date
    Jun 2008
    Answers
    1

    Re: sizeof() operator

    It depends on size of integer.
    /* Assuming size of int as 32 bits */
    10 4


  7. #7
    Junior Member
    Join Date
    Jan 2008
    Answers
    3

    Re: sizeof() operator

    Hi,

    A principal use of the sizeof operator is in communication with routines such as storage allocators. A storage-allocation function might accept a size (in bytes)and allocate and return a pointer to void.

    Another use of the sizeof operator is to compute the number of elements in an array:
    sizeof array / sizeof array[0]

    I have not come across any use as below

    Quote Originally Posted by jaiprabuk View Post
    give the o/p for the following code ....also explain how...


    int i=10,j;
    j=sizeof(++i + ++i);
    printf("%d %d",i,j);
    however

    generic output is
    10 and X(X=One word Length)

    10 and 2(on a 16 bit )
    10 and 4(on a 32 bit )
    10 and 8(on a 64 bit )

    Here as we may expect the sizeof has an expression in it and we assume it to be evaluated. But this is not the case as the ISO C standard define the sizeof opeator having constraint as
    "The sizeof operator shall not be applied to an expression that has function type or an incomplete type, to the parenthesized name of such a type, or to an expression that designates a bit-field member."

    The operand of a sizeof operator is usually not evaluated .

    I have referred Committee Draft Septermber 7, 2007 ISO/IEC 9899:TC3

    Regards,
    younus saleem


  8. #8
    Junior Member
    Join Date
    Jun 2008
    Answers
    2

    Re: sizeof() operator

    i=12
    j=2(dos)
    j=4(windows)


  9. #9
    Junior Member
    Join Date
    Jun 2008
    Answers
    1

    Re: sizeof() operator

    Yes,I would agree to Younus.sizeof() doesn't allow any operation inside it.That's why the o/p should be 10 and 4 or 2 depending on the configuration of the user's m/c.


  10. #10
    Junior Member
    Join Date
    Aug 2008
    Answers
    2

    Re: sizeof() operator

    4, 8
    sizeof operator gives the no of bits it can occupy.


  11.  Sponsored Ads
    Ad


     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact