I need help

This is a discussion on I need help within the C++ Programming forums, part of the General Programming Boards category; I have this function Code: str[10]="ABCDEFGHJI"; int strOffset; display(str+strOffset); I just want to know what happen if strOffset is greater ...

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    51

    I need help

    I have this function
    Code:
    str[10]="ABCDEFGHJI";
    int strOffset;
    
    display(str+strOffset);
    I just want to know what happen if strOffset is greater than 10. What will be pass to the display function. Will it be a empty string or a null character or neither of them?

    I Tried to use if to find out what will be pass to display but I cant seem to get it.

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    What will happen doesn't matter since it will be undefined behavior.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,174
    More precisely, ANYTHING is allowed to happen because it is undefined behaviour. A value of zero might be passed to display(). A reformat of your boot drive might be initiated, so display() might never be called. Either way, the behaviour is correct. That is what "undefined" means in the standard: there are no defined limits on what is allowed to happen. Anything an implementation chooses to do is deemed correct.
    Right 98% of the time, and don't care about the other 3%.

  4. #4
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by grumpy View Post
    More precisely, ANYTHING is allowed to happen because it is undefined behaviour. A value of zero might be passed to display(). A reformat of your boot drive might be initiated, so display() might never be called. Either way, the behaviour is correct. That is what "undefined" means in the standard: there are no defined limits on what is allowed to happen. Anything an implementation chooses to do is deemed correct.
    Umm...the red thing is a link grumpy(psst click on it).
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,174
    I knew that Andrew. I was responding to your words "doesn't matter".
    Right 98% of the time, and don't care about the other 3%.

  6. #6
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by grumpy View Post
    I knew that Andrew. I was responding to your words "doesn't matter".
    More or less just joking with you. The article posted explained why it "didn't matter" to discuss what would happen. Either/or, I was just playing around and meant no offense.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

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