• Why isn't my image appearing in the browser? HTML5?

    This is the code I have so far: <!DOCTYPE html> <html> <head> <title> An Original </title> </head> <body> <p>This is my very first website.</p> <p> I'm going to try and insert an image into my code. I hope it works.</p> <img... show more
    This is the code I have so far: <!DOCTYPE html> <html> <head> <title> An Original </title> </head> <body> <p>This is my very first website.</p> <p> I'm going to try and insert an image into my code. I hope it works.</p> <img src="swimming.jpg" width="640" height="433"/> </body> </html> I have index.html in the same folder as the image.
    7 answers · 16 hours ago
  • I want to graduate as a graphic designer but some family members say the market is too flooded, I wont get a good job is this true?

    Best answer: Don't let them stop you from doing what you want to do! There will always be a need for graphic design.
    Best answer: Don't let them stop you from doing what you want to do! There will always be a need for graphic design.
    20 answers · 5 days ago
  • Some men are very hot and handsome...they flirt with you all the time... But they do the same with every other chick?

    Best answer: yes dont trust that type ,.cause they are not honest
    Best answer: yes dont trust that type ,.cause they are not honest
    9 answers · 2 days ago
  • What is the actual point in using pointers?

    Best answer: 1) Pointers ARE NOT used to allocate memory. You are confusing 2 different questions: heap vs stack memory, and data types. A pointer is, technically, an address and nothing else (and from a language point of view it is a pair address/type) If you does this: int v; int *a=&v; a is a pointer. Yet, you've... show more
    Best answer: 1) Pointers ARE NOT used to allocate memory.
    You are confusing 2 different questions: heap vs stack memory, and data types.

    A pointer is, technically, an address and nothing else (and from a language point of view it is a pair address/type)

    If you does this:
    int v;
    int *a=&v;
    a is a pointer. Yet, you've not used to allocate memory. The value v is a value (in the stack; that is a local variable, allocated by the compiler). a is a pointer, that is also a value in the stack, but this value is to be understood as an address of some place in the memory. After I type a=&v, a is the address where v is stored (a is the address in the stack where the compiler decided to store v)

    2) Your code is not working
    You CANNOT type
    char *a;
    a='h';

    a is supposed to be the address of a variable. That is, a 32 bits integer, or even a 64 bits integer, on most machines.
    And what you are trying to store in it is a char (a 8 bits integer, usually representing an ASCII code)

    The only reason why it may compile in with some compiler (with certainly a warning) is because 8 is smaller than 32 or 64. So the is room to store 104 ('h' is another name of 104) in a variable that is supposed to contain a 32/64 bits address.

    But you could have then, as well, typed
    char *a;
    a=1234;
    it would make exactly as many sense (you store an int, 1234, in a variable declared as an address. Sure if you insist on doing it, with a warning, the compiler can do it, since, after all, an address is a sort of int. But that makes no sense.
    If you try afterward to use variable a as a pointer, for example by derefencing it, you will get a segmentation fault.
    For example, if you try to
    printf("%c\n", *a);
    as you should be able to do if a were a valid pointer, it will try to print the "char" stored at address 1234 of the memory (or at address 104 is a='h'), and chances are that those address do not belong to your process, so you get a segmentation fault (if you are very lucky, or, I should say, very unlucky, those address 1234 or 104 belong to your process, and you won't get a segmentation fault. But you code will do some BS, since, obviously printing the content of address 1234 or 104 was not at all your intention)


    3) The correct version of your code would rather be
    char *a;
    ...
    *a='h';
    (a is the address of a char. Hence *a is that char pointed by a. So you can change the value stored at address a by modifying *a)

    Without anything in place of the "...", though, that would also lead to a segmentation fault.
    Because, as all variables, its initial value is not specified.
    When you declare
    int v;
    v could have any random value, before you initiazed it with a value (a number) that makes sense.

    Likewise, when you declare
    char *a;
    a could have any random value before you initialize it with a value (an address) that makes sense.
    So if you try to read or write content of *a, you are trying to read or write the content of a random place (even maybe a non existing place) of the memory. That can't end well.

    So for example you could do this:
    char *a;
    char v='h';
    a=&v:
    *a='x";

    a is a variable of type "address of a char".
    v is a variable of type "char", whose value is 'h' (that is 104)
    a value (which was a random uninitialized value) is changed to the address of v.
    So, now, address of v is a. And its content is *a (hence *a is 'h')
    Then after the execution of
    *a='x'
    value stored at address a is change to 'x'.
    Since a is the address of v, that means that value of v has changed to 'x'.

    Of course, this has no interest at all (see later of interest). But that is how you use pointer.


    4) Another thing you could have in place of my "..." is a memory allocation
    char *a;
    a=malloc(1);
    *a='x';

    That is probably what you are referring to when saying "you need them to allocate memory". Because if you want to allocale memory in the heap, with malloc, then, since malloc return a pointer, you have no choice but using pointers to access this memory.
    There is no variable whose content is 'x' in this code. The only way to read (or replace) that 'x' is to access to *a


    So summary of all these 4 points: you have 2 questions here
    1) Why to I need pointers
    2) Why to I need "malloc" (or new in C++)

    5) For pointers, you need them whenever you want to give an address
    For example, if you want to write a function sqr, to compute the square of a number. You have two choices

    You could write
    int sqr(int x){
    return x*x;
    }
    So the square is computed, returned, and the caller may store the returned value in a variable itself, like this:
    int y=sqr(x);

    Or, you could, instead of using return values, say to function sqr : compute the square of this number (x) and store your self the result at this address (adr)
    void sqr(int x, int *y){
    *y=x*x:
    }

    So the caller does not store itself the result in a variable. Instead it gives sqr the address of a place where sqr is supposed to store the result. Like this:
    int y;
    sqr(x, &y);


    If you create a function whose results are two different values, that is pretty much your only choice. For example, if you want to compute both square and cube of a number. You could do this:
    int sqr(int x){
    return x*x;
    }
    int cube(int x){
    return x*x*x;
    }
    int a,b;
    a=sqr(x);
    b=cube(x);
    And use both. But that means that cube will compute x*x (x*x*x means (x*x)*x) that has already been computed.

    So, to avoid computation redundancy, you may want to do this:
    void sqrAndCube(int x, int *y, int *z){
    *y=x*x;
    *z=(*y)*x;
    }
    int a,b;
    sqrAndCube(x,&a,&b);



    There are far more clever examples than that, better reason to use pointer (for example, if you need a circular list)
    But that is a basic one.


    6) As far as "why malloc"
    That is "why to I need to allocate 'with pointer' memory, since all variables are allocated some place".
    Well sometimes you can't know while programming how many memory you will need.
    So there is no way you can allocate directly as a variable the memory.

    Plus, the stack has often a limited size. So if you need lot of memory, you can't put it is the stack (as local memory)
    And even if you can, it can slow down a lot the speed of processus if you use too much stack memory.
    6 answers · 15 hours ago
  • What should I do after learning Java?

    5 answers · 7 hours ago
  • Programming Question?

    4 answers · 2 hours ago
  • How much computer skill do you need to use Linux?

    I am the poster child for having no knowledge of computers and programming whatsoever, but the thought of trying Linux has always interested me (especially since I'm getting really fed up with Windows 10 and I'm not a huge Mac fan). However, from what I've heard, it's pretty tech heavy. So, exactly... show more
    I am the poster child for having no knowledge of computers and programming whatsoever, but the thought of trying Linux has always interested me (especially since I'm getting really fed up with Windows 10 and I'm not a huge Mac fan). However, from what I've heard, it's pretty tech heavy. So, exactly how much programming skill do I need to use Linux? I'm not planning on doing any crazy, in-depth stuff, I just need enough knowledge to use it like a normal, non-professional programmer person.
    10 answers · 6 days ago
  • Whats the code to import a datetime (yaer, month and day) in python?

    Best answer: import datetime
    now = datetime.datetime.now ()
    print (now.month, now.day, now.year)
    Best answer: import datetime
    now = datetime.datetime.now ()
    print (now.month, now.day, now.year)
    5 answers · 2 days ago
  • I want to enter code?

    4 answers · 1 day ago
  • Plese give me flowchart of this program?

    11 answers · 1 week ago
  • What's wrong with my c+ comment?

    Best answer: That compiles and works just fine here. Output: 2, 3, 5, Press any key to continue . . . If you remove the multiple-line comment at the end of main(), you'll get the same output. What were you expecting? You can use /* and */ to surround comments in C++. That's the only way to make a single comment... show more
    Best answer: That compiles and works just fine here. Output:

    2, 3, 5, Press any key to continue . . .

    If you remove the multiple-line comment at the end of main(), you'll get the same output.
    What were you expecting?

    You can use /* and */ to surround comments in C++. That's the only way to make a single comment stretch over multiple lines. However, using // is almost universally used for "end-of-line" comments. For example:

    while (sum < 5) // Repeat until the sum is at least 5

    It's also common to use the same idea in multiple line comments (aka "block comments") so that the lines stand out as comments, not code:

    // - - - - - - - - - - - - - - - - - - -
    // a=0, b=1, sum=0+1
    // a=b, b=sum, sum=a+b
    //
    // a=1 because a=b and b=sum
    // b=2 because b=1+1, since b=sum, sum=a+b sum=1+1
    [etc.]
    // - - - - - - - - - - - - - - - - - - -

    The line of hyphens (stars, equal signs, etc.) is less common. I use it as a "horizontal rule" that you see in word processors and web pages sometimes to separate sections.
    6 answers · 4 days ago
  • Is there source where can I learn programming, Java, html, css, apps but more proffessional and advanced level?

    I know some basic that I learned from books but I don't know how and where to find information so that I could be able to actually make professional applications. What do I need for creating a game? Where should I start to find some advanced materials?
    I know some basic that I learned from books but I don't know how and where to find information so that I could be able to actually make professional applications. What do I need for creating a game? Where should I start to find some advanced materials?
    4 answers · 2 days ago
  • Apparently scripting is easier than programming. Is "scripter" a job?

    I know that some game designers script, and I've heard of the job title "scripter". If such a job title exists, where else do they work besides games (e.g. Websites, software, etc)
    I know that some game designers script, and I've heard of the job title "scripter". If such a job title exists, where else do they work besides games (e.g. Websites, software, etc)
    4 answers · 2 days ago
  • How do you say crap in binary code?

    4 answers · 2 days ago
  • Can i learn C++ in one hour?

    23 answers · 1 week ago