What is legal and what is illegal?

This is a discussion on What is legal and what is illegal? within the C Programming forums, part of the General Programming Boards category; Code: int i, *p, *q; // is this legal or illegal? Which one is legal and what is not? p ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    91

    What is legal and what is illegal?

    Code:
    int i, *p, *q;
    
    // is this legal or illegal? Which one is legal and what is not?
    
    p = i;
    * p = &i;
    &p = q;
    p = &q;
    p = *&q;
    p =q;
    p = *q;
    *p = q;
    *p = *q;
    
    //Just wondering which of these are legal in all situations..

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Ok... that was lame.

    Code:
    p = i;
    * p = &i;
    &p = q;
    p = &q;
    p = *&q;
    p =q;
    p = *q;
    *p = q;
    *p = *q;

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,437
    Create a program, see which ones generate error messages, hence the answer.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Hey... why you gotta pull the moderator card on me, Salem? I am sorry

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