Help

This is a discussion on Help within the C++ Programming forums, part of the General Programming Boards category; I've got an exercise due that make no sence to me can someone please explain this to me. The assignment ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    11

    Help

    I've got an exercise due that make no sence to me can someone please explain this to me.

    The assignment says given the following definition statement

    char k, *p, n[3], **q, *x[4];

    What is the data type for the following expressions
    Note: Each expression is an rvalue (a constant)

    k p
    k+2 p+2
    &k &p
    &k+2 p[2]

    and the list goes on

    I understand char k= 'k' is a char but what about k+2 ?
    If your creating char variable wouldn't they all be char

    Help Please

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    88
    I don't understand your examples...

    k+2 is 'm' because k contains 'k' and 'k' (which is 107) plus 2 is 109 (which is 'm')

    char and int are the same, there are only interpreted differently!

    p+2 is a pointer operation!
    for example p is a pointer to a string "Hello World"
    than p+2 would return "llo World"!
    It just adds 2 to the offset...

    &k returnes the offset of k!

    &k+2
    is just the same as p+2 becasuse &k is a offset and you add 2 to the offset...

    and *(p+2) or p[0] are exactly the same!
    Hope you don't mind my bad english, I'm Austrian!

  3. #3
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Please, for the love of god, post descriptive titles. "Help" doesn't give the reader very much information, and it sucks when you're searching the board and can't find what you want because everything is CALLED HELP FOR ****S SAKE

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    11
    ok bunny I'll change my tiltle, thanks for all your help!!

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    11
    Thats the problem Shade I don't really understand the the problem either. If its k+2 is it still a char because it started out as char ?

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