Thread: find the output!

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    32

    find the output!

    hi friends!

    plz find the output (and hence correct option)of the following piece of code and explain if possible.


    35.Consider the following program
    main(){
    int a[5]={1,3,6,7,0};
    int *b;
    b=&a[2];
    }
    The value of b[-1] is
    (a) 1
    (b) 3
    (c) -6
    (d) none





    28. What does the following code do?
    fn(int n,int p,int r){
    static int a=p;
    switch(n){
    case 4:a+=a*r;
    case 3:a+=a*r;
    case 2:a+=a*r;
    case 1:a+=a*r;}}
    (a)computes simple interest for one year
    (b)computes amount on compound interest for 1 to 4 years
    (c)computes simple interest for four year
    (d)computes compound interst for 1 year


    36. # define prod(a,b)=a*b
    main(){
    int x=2;
    int y=3;
    printf("%d",prod(x+2,y-10)); }
    the output of the program is
    (a) 8
    (b) 6
    (c) 7
    (d) None

    thanks!
    samir

  2. #2
    former member Brain Cell's Avatar
    Join Date
    Feb 2004
    Posts
    472
    This thread will solve your real problem :
    http://cboard.cprogramming.com/showthread.php?t=25765
    My Tutorials :
    - Bad programming practices in : C
    - C\C++ Tips
    (constrcutive criticism is very welcome)


    - Brain Cell

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    120
    Heres another helpful tip

    Homework

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I can't believe people actually put homework quizzes and tests on here....complete with the question number next to them.

    Here's your sign. Wear it proudly.

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    120
    Maybe its the spammer attitude. He posts his homework on every programming board he can find and maybe, just maybe some poor soul answers his questions.

    Once you geta job, you can't cheat like that. If I were to actually post sample code of what I am working on for help, I could get fired for dilvugence of proprietary info...Of course, I did my own homework in school so I know what I'm doing

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I haven't even stepped foot inside of a C programming class and I know what I'm doing.

    ::walks out shaking his head::

  7. #7
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    ahh, gotta love crappy tests, and lazy people too
    28. I clearly see what it's trying to do, but considering the fact that the function doesn't actually return anything, I'd say that it does nothing. There's no other way you'll ever get the values it computes out.

    36. Since when did #defines have an = in them? This one does nothing; not even compile.

    35. I'll take the easy way out. If main neglects to return anything, my Foobar United Standard C Compiler produces an app that trashes the stack when main returns, killing all your variables. Of course one could say, "I mean what is the value of b[-1] right after the line 'b = &a[2];', but they most certainly didn't say that. Suppose I decide to tell you what the value of b[-1] is right after the line 'int *b;'... this fits well with #28 I think; sure the function does stuff with numbers and stuff, but if you want to know more about what a particular variable is you need to say both what variable you're interested in and when you're interested in it.

    You know, this crap is why neverplan to ever take another programming class. I'm an undergraduate studying 300 level maths right now, and stuff is hard, and complicated. But the profs know what they're talking about. I'd hate to think how many more junk classes I'd have to sit through before I found a professor who knew anything. Too bad; because both computer science theory and computer programming interest me. But beginning with high school and "how to learn obscenely flawed C++ on an obscenely antiquated compiler" and "how to learn java while actually learning nothing at all about it", I just stopped there and program in C as a hobby.

    [/rant]
    hello, internet!

  8. #8
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    My profs aren't that lame...

  9. #9
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I want to go to college so I can learn how to compute compounded interest in C.

    GAWD.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 10:08 PM
  2. Having trouble making a function do what I want.
    By Shamino in forum C++ Programming
    Replies: 9
    Last Post: 12-07-2007, 11:20 AM
  3. Output an array in a textbox
    By Diablo02 in forum C# Programming
    Replies: 5
    Last Post: 10-18-2007, 03:56 AM
  4. Trying to store system(command) Output
    By punxworm in forum C++ Programming
    Replies: 5
    Last Post: 04-20-2005, 06:46 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM