Thread: Answers plz!!!

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    10

    Answers plz!!!

    QUESTION 1.

    In the following code a peice of info is printed at each PR can people help me give me what is gona be printed. thanks.

    Code:
    #include "defs.h2
    
    int a[] = {0,1,2,3,4};
    
    void main(void)
    {
    int i, *p;
    
    for(i = 0;i <= 4; i++) PR(d, a[i]);
    NL;
    for(p = &a[0]; p <= &a[4]; p++) PR(d, p[i]);
    NL;
    for(p = a;, i = 0; p + i <= a + 4; p++, i++)
    PR(d, *(p + i));
    NL;
    for (p = a + 4; p >= a; p--) PR(d, *p);
    NL;
    for(p = a + 4, i = 0; i <= 4; i++) PR(d, p[-i]);
    NL;
    for(p = a +4; p >= a; p--) PR(d, a[p - a]);
    NL;
    }
    QUESTION 2
    Can any provide me with the print out valuers for the followong 4 printf statments??
    Code:
    void main(void)
    {
    int x;
    
    x = - 3 + 4 * 5 - 6;
    printf("%d\n", x);
    
    x = 3 + 4 % 5 - 6;
    printf("%d\n", x);
    
    x = - 3 * 4 % - 6 / 5;
    printf("%X\n", x);
    
    x = (7 + 6) % 5 / 2;
    printf("%X\n", x);
    }


    P.S. Thanks Amill for everyone's help this is study for my exam in januruary,

    thanks.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    How about you compile it and run it? And turn the warnings up so it'll catch the garbage you have (like having main() declared as returning void).

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote Originally Posted by tipp2007 View Post
    QUESTION 1.

    In the following code a peice of info is printed at each PR can people help me give me what is gona be printed. thanks.
    Given the fact that you haven't shown any code related to those PR functions/macros/whatevers, it will be difficult for me to divine an answer as to what output they'll produce. I'll have to resort to other methods... magic 8-Ball says "Ask again later."
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Registered User
    Join Date
    Jul 2007
    Posts
    10
    Sound by the way there is answers and outputs, but obivously your to my much of a smart azzz to know them, thanks for nothing!!!!

  5. #5
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by tipp2007 View Post
    Sound by the way there is answers and outputs, but obivously your to my much of a smart azzz to know them, thanks for nothing!!!!
    You didn't provide enough information to find out what the output is, and then you complain because you don't understand what we say. If this is your attitude, I have something to tell you:

    Go write your exam in January and we'll see who the smart guy is.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Actually, there won't be any output. Why? Well, you're missing a " in the #include, for one. void main() is also non-standard, and int main() should be used instead, but if that's what the question said then you can't really do much about it I suppose. Put your instructor online so we can yell at him/her.

    Question 2 looks a little more complete, so . . . it's actually quite simple to solve. You need to know only a few things:
    • What the &#37;X format specifier does.
    • The operator precedence of arithmetic operators.

    %X prints a hexadecimal number, with the letters in uppercase, as you can easily determine from documentation. http://www.cppreference.com/stdio/printf.html

    Just like in math, * and / are evaluated before (have higher precedence than) + and -, and the unary negation (minus sign) has a higher precedence still, so an expression like "- 3 + 4 * 5 - 6" becomes "(-3) + (4 * 5) - 6". You can figure that out, right?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Day Dreamer
    Join Date
    Apr 2007
    Posts
    45
    Getting answers from us wont really help if you dont try to find solutions yourself.
    Try them out first and then post the problems you face.
    I would love to change the world but they dont give me the source code!

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Well it may well be compiler dependent, but assuming usage of VS2005, the correct answer to the first one is that it will output this:
    Code:
    error C2001: newline in constant
    Gotta love trick questions huh!
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  3. answers for Ivor Horton's Beginning C++?
    By 7stud in forum C++ Programming
    Replies: 1
    Last Post: 03-17-2005, 12:13 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM