Results 1 to 8 of 8

Thread: sizeof and strlen

  1. #1
    Junior Member
    Join Date
    Feb 2007
    Answers
    3

    sizeof and strlen

    Why sizeof is an operator and strlen is a function?


  2. #2
    Contributing Member
    Join Date
    Mar 2007
    Answers
    34

    Re: sizeof and strlen

    strlen function is use to get the string length
    while size of is used to get the size of varriable


  3. #3
    Junior Member
    Join Date
    Mar 2007
    Answers
    1

    Re: sizeof and strlen

    Hello,

    sizeof is called as a operator because it operates means he never sends a parameter .
    Whille strlen sends the string mention and returns integer equivalent to the number of char in string.



  4. #4
    Junior Member
    Join Date
    Oct 2006
    Answers
    5

    Re: sizeof and strlen

    strlen is a function only because it always returns a value.......
    Sizeof on the other hand never returns any value..... thus an operator....


  5. #5
    Junior Member
    Join Date
    Feb 2006
    Answers
    8

    Re: sizeof and strlen

    sizeof is done at compile time. strlen is done at runtime.
    char ac[100] = "This is a test";
    int i = sizeof(ac); // i = 100
    int j = strlen(ac); // j = 14
    char *pc = ac;
    int k = sizeof(pc); // k = 4 (pointer size)
    int m = strlen(pc); // m = 14


  6. #6

    Smile Re: sizeof and strlen

    Quote Originally Posted by sat_yucky View Post
    strlen is a function only because it always returns a value.......
    Sizeof on the other hand never returns any value..... thus an operator....

    So you mean to say that if a function doesnt return anything then its an opearator rather than a function ?
    In that case all void functions are operators ...


  7. #7
    Expert Member
    Join Date
    Nov 2006
    Answers
    518

    Re: sizeof and strlen

    Hay, it has nothing to do with whether it takes arguments or not or returns any value or not.

    Its only coz sizeof() is done at compile time.
    I strongly agree with “mef526”

    Lack of WILL POWER has caused more failure than
    lack of INTELLIGENCE or ABILITY.

    -sutnarcha-

  8. #8

    Re: sizeof and strlen

    Quote Originally Posted by sutnarcha View Post
    Hay, it has nothing to do with whether it takes arguments or not or returns any value or not.

    Its only coz sizeof() is done at compile time.
    I strongly agree with “mef526”

    Yes , even i agree over that .. ..
    “mef526” is correct. sizeof() is done at compile time and strlen() is done at runtime. and that is the only reason why ANSI C++ treats strlen() as function and sizeof() as operator.


  9.  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