1. DLP Flash Christmas Competition + Writing Marathon 2024!

    Competition topic: Magical New Year!

    Marathon goal? Crank out words!

    Check the marathon thread or competition thread for details.

    Dismiss Notice
  2. Hi there, Guest

    Only registered users can really experience what DLP has to offer. Many forums are only accessible if you have an account. Why don't you register?
    Dismiss Notice
  3. Introducing for your Perusing Pleasure

    New Thread Thursday
    +
    Shit Post Sunday

    READ ME
    Dismiss Notice

Programming !! :D

Discussion in 'Tech Support' started by Skykes, Dec 7, 2010.

  1. KrzaQ

    KrzaQ Denarii Host DLP Supporter

    Joined:
    May 9, 2008
    Messages:
    1,404
    Location:
    Poland
    That's simple. When you pass arguments by value (no pointer, no reference), they're copied and all operations are performed on said copies.

    try
    Code:
    float exchange (float &a, float &b)
    {
        float aux;
        aux=a;
        a=b;
        b=aux;
    }
    
    exchange (x[i], x[j])
    
     
  2. Nukular Winter

    Nukular Winter The Chosen One DLP Supporter

    Joined:
    Jun 8, 2006
    Messages:
    2,216
    Location:
    Seattle
    Krazq is correct that variable scope is your issue, but his answer doesn't quite work either.
     
  3. KrzaQ

    KrzaQ Denarii Host DLP Supporter

    Joined:
    May 9, 2008
    Messages:
    1,404
    Location:
    Poland
    I beg to differ



    While we're on this topic, how can you explain this?
     
    Last edited: Dec 8, 2010
  4. Nukular Winter

    Nukular Winter The Chosen One DLP Supporter

    Joined:
    Jun 8, 2006
    Messages:
    2,216
    Location:
    Seattle
    Sorry if I wasn't clear. Obviously C allows you great latitude with abusing variable type and your answer *works*, but since you didn't use explicit typecasting if I was the TA and you turned that in I would assume that you didn't understand the difference between float, &float, and *float and would grade you accordingly.
     
  5. Heleor

    Heleor EsperJones DLP Supporter

    Joined:
    Mar 3, 2006
    Messages:
    1,431
    Location:
    Seattle, WA
    Nukular... why the hell would you mark that down? If you /do/ use explicit typecasting, I understand marking someone down, but a float and a float reference (&float) are exactly the same type, and should be used that way.
     
  6. Nukular Winter

    Nukular Winter The Chosen One DLP Supporter

    Joined:
    Jun 8, 2006
    Messages:
    2,216
    Location:
    Seattle
    In an intro to programming class?
     
  7. Heleor

    Heleor EsperJones DLP Supporter

    Joined:
    Mar 3, 2006
    Messages:
    1,431
    Location:
    Seattle, WA
    Typically it's taught that variables are passed either by value (a copy is made) or by reference (treat it as the actual value). Adding a by-reference flag lets you use it as if it wasn't part of the function at all.

    float and &float are not different types, and should never be treated that way, especially in an intro class.

    Then again, I don't believe C should be an intro class, but most languages have a byref and byval declaration.
     
  8. KrzaQ

    KrzaQ Denarii Host DLP Supporter

    Joined:
    May 9, 2008
    Messages:
    1,404
    Location:
    Poland
    I don't quite understand why would you makt it down. Do you consider using explicit typecasting whenever possible a good coding habit?
     
  9. Nukular Winter

    Nukular Winter The Chosen One DLP Supporter

    Joined:
    Jun 8, 2006
    Messages:
    2,216
    Location:
    Seattle
    I just looked it up to see if I was smoking crack, and apparently that's actually how you pass by reference in that newfangled C++. (I learned C and pretty much used it for everything). Humbug.

    In good old C, passing by reference would look something like this:

    Code:
    #include <stdio.h>
    
    void swap(int *i, int *j) {
       int temp = *i;
       *i = *j;
       *j = temp;
    }
    
    void main() {
       int a = 42, b = 69;
       printf("Before. a: %d, b: %d\n", a, b);
       swap(&a, &b);
       printf("After . a: %d, b: %d\n", a, b);
    }
    
    At any rate, Mea Culpa and full points to you.

    /Get off my lawn
     
  10. Sesc

    Sesc Slytherin at Heart Moderator

    Joined:
    Dec 20, 2007
    Messages:
    6,216
    Gender:
    Male
    Location:
    Blocksberg, Germany
    ^ That's how I'd have done it too. Seems the most obvious way to me. But then again, I'm in the same boat as Nukular -- I learned C, not C++.
     
    Last edited: Dec 8, 2010
  11. Kthr

    Kthr Unspeakable DLP Supporter

    Joined:
    Sep 1, 2008
    Messages:
    713
    Location:
    São Paulo, Brazil
    Which is what I ended up doing. Well, at least I solved most of the question I had for the exam tomorow, now I'm off to go shoot some zombies on LFD2. Thanks for the help guys.

    Edit to keep the topic alive: What kind of language most of you use to program nowadays? I've been drifting a bit along my C class this semester, and probably will need to learn some assembly for a couple projects I'm helping out.
     
    Last edited: Dec 9, 2010
  12. Heleor

    Heleor EsperJones DLP Supporter

    Joined:
    Mar 3, 2006
    Messages:
    1,431
    Location:
    Seattle, WA
    I use Java a lot at my job. I use perl a lot more than I would like to as well. :-|
     
  13. Perspicacity

    Perspicacity Destroyer of Worlds ~ Prestige ~ DLP Supporter

    Joined:
    Nov 27, 2007
    Messages:
    1,022
    Location:
    Where idiots are not legally permitted to vote
    High Score:
    3,994
    I mostly write in C and C++ and am most competent in C. I cut my teeth in programming writing Vax-11 assembly.
     
  14. Oz

    Oz For Zombie. Moderator DLP Supporter

    Joined:
    Jan 31, 2008
    Messages:
    9,028
    Gender:
    Female
    Location:
    Baile Átha Cliath
    Java and Python mostly. I didn't spend too much time learning C++ before my mind wandered onto other things. <.<
     
  15. Sesc

    Sesc Slytherin at Heart Moderator

    Joined:
    Dec 20, 2007
    Messages:
    6,216
    Gender:
    Male
    Location:
    Blocksberg, Germany
    I started with C, then did Delphi/Pascal for OOP. Those are the ones I feel most comfortable in. For Uni, I used Fortran (yes, really) and now they make me learn Java. So currently, I want Fortran back :s
     
  16. silverlasso

    silverlasso Minister of Magic DLP Supporter

    Joined:
    Dec 7, 2007
    Messages:
    1,302
    Location:
    San Francisco
    I first learned Python, then some C, then Java. I mostly use Java and Python nowadays, although I'm trying to work my way through SICP at the moment and in the process am learning Scheme.
     
  17. Grubdubdub

    Grubdubdub Supreme Mugwump

    Joined:
    Feb 22, 2008
    Messages:
    1,604
    Learned Java for 2 years, though I'm afraid I don't remember much anymore...
     
  18. Alindrome

    Alindrome A bigger, darker mark DLP Supporter Retired Staff

    Joined:
    Apr 9, 2009
    Messages:
    2,771
    Gender:
    Female
    Location:
    England
    I started with Ruby, was taught Pascal, and am studying HTML and XML, Visual Basic, Java, and am hoping to study C++.
     
  19. fuubar

    fuubar Headmaster

    Joined:
    Nov 17, 2007
    Messages:
    1,101
    Hmmm lemme see, this semester ACL2 (a subset of Common Lisp), Java, C++, C#, Objective-C, and a little bit of Python and Matlab when the occasion called for it (technically Dalvik as well but thats basically Java). God this semester sucked balls.
     
  20. KrzaQ

    KrzaQ Denarii Host DLP Supporter

    Joined:
    May 9, 2008
    Messages:
    1,404
    Location:
    Poland
    I wouldn't call HTML/XML a programming language.

    Anyway, I'm pretty good with C/C++ and I've written a fair share of helloworlds in Ruby, PHP and x86 assembly (Intel syntax). I also coded a little in Java and MatLab's scripting language.

    Should I mention RegExp as well?
     
Loading...