all 27 comments

sorted by: hot top controversial new old
[–] 69 points 11 months ago (5 children)

You can't perform calculations on a string

Laugh in C

  • source
  • hideshow 5 child comments
  • [–] 30 points 11 months ago (3 children)
  • [–] 30 points 11 months ago (2 children)
  • [–] 9 points 11 months ago
    #include <stdbool.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    char* addStrings(char* as, char*bs){
            int aL=strlen(as);
            int bL=strlen(bs);
            if (aL<bL){
                    char* temp=bs;
                    int tL=bL;
                    bs=as;
                    bL=aL;
                    as=temp;
                    aL=tL;
            }
            char* cs = malloc(aL+2);
            cs[aL+1]='\0';
            bool carry = false;
            int bi=bL-1;
            for(int ai=aL-1; ai>=0; ai--,bi--){
                    char a=as[ai];
                    char b='0';
                    if(bi>=0)b=bs[bi];
                    char c=a+b-'0';
                    if(carry)c++;
                    carry=c>'9';
                    if(carry)c-=10;
                    cs[ai+1]=c;
            }
            if(carry) cs[0]='1';
            else cs[0]='0';
            return cs;
    }
    
    int main(int argc, char**args){
            printf("%s + %s = %s\n", args[1] , args[2] , addStrings(args[1] , args[2]));
    }
    
  • source
  • parent
  • [–] 58 points 11 months ago (1 child)

    In computing, whole numbers are referred to as integers

    they are known as integers outside of computing too lol

  • source
  • hideshow 1 child comment
  • [–] 7 points 11 months ago

    Yeah, but in computing (well, specifically the language this slide is about) they're referred to as integers and not referred to as "whole numbers" or any other synonym. If you're looking up something to do with integers in the documentation, you need to have the word "integer" in your vocabulary as "the" way to refer to numbers without decimal places to find what you're looking for. Same way you need to know "string" instead of "word" or "text field" or "sentence".

  • source
  • parent
  • [–] 47 points 11 months ago (3 children)

    JavaScript trying to look nonchalant in the corner.

  • source
  • hideshow 3 child comments
  • [–] 23 points 11 months ago (3 children)

    Amazingly you can store all sorts of things in variables.

  • source
  • hideshow 3 child comments
  • [–] 13 points 11 months ago (2 children)

    Including nothing. Actually, depending on the language, multiple types of nothing (null vs uninitialized)

  • source
  • parent
  • hideshow 2 child comments
  • [–] 5 points 11 months ago

    actually, you can even store pointers to nothing in memory. you just do:

    void x;
    void* x_ptr = &x;
    

    then you can use it to invoke functions that take no arguments like this:

    void open_texteditor (void editor_choice)
    {
        // do nothing with the editor_choice because there is only one sensible editor
        open_nano(); 
        return void;
    }
    void favorite_texteditor;
    void result = open_texteditor(favorite_texteditor);
    print_error_on_bad_result(result);
    

    (note that this is a joke comment)

  • source
  • parent
  • [–] 20 points 11 months ago

    I mean, in Python, Int() literally is a pre - formed function for per - forming math on strings.

  • source
  • [–] 22 points 11 months ago

    comp sci brainrot

  • source
  • [–] 6 points 11 months ago

    You can very much perform calculations on strings, and its a very cool thing, but i think thats wayyy above the level that this presentation is meant for cause you probably should know what integers are before that, even outside of programming...

  • source
  • [–] 10 points 11 months ago (4 children)

    This is programming 101 from which century?

  • source
  • hideshow 4 child comments
  • [–] [S] 0 points 11 months ago (3 children)

    does it say programming 101 somewhere

  • source
  • parent
  • hideshow 3 child comments
  • [–] 2 points 11 months ago (2 children)

    No programming 101 is what happens when you perform calculations on a string.

    Please do try to keep up.

  • source
  • parent
  • hideshow 2 child comments
  • [–] 4 points 11 months ago

    "preform calculations"

  • source
  • [–] 3 points 11 months ago (1 child)

    Is it all right to postform calculations on a string?

  • source
  • hideshow 1 child comment