Search:

Type: Posts; User: laserlight

Page 1 of 20 1 2 3 4

Search: Search took 0.14 seconds.

  1. Look at this example that you yourself wrote: ...

    Look at this example that you yourself wrote:

    int fun ( int *p )
    {
    *p = 20;

    return p;
    }
    Here is the same function, but with the place in the syntax where the return type is...
  2. Check the return type of the function. Is it a...

    Check the return type of the function. Is it a pointer type? If yes, then the function returns a pointer.
  3. Replies
    4
    Views
    44

    At the top of foo.c, declare x: extern int x;...

    At the top of foo.c, declare x:

    extern int x;

    You also need to #include <stdio.h> in foo.c
  4. Only mathematically. In this context, 20 is an...

    Only mathematically. In this context, 20 is an int, whereas 0061FF28 is an address (i.e., the value of a pointer). The function is declared as returning an int, not a pointer.


    Since you want to...
  5. Replies
    4
    Views
    44

    Yes, a global variable indeed has global scope,...

    Yes, a global variable indeed has global scope, i.e., every use of that name that has not been shadowed by another variable whose name has a more local scope refers to that global variable.
  6. Replies
    4
    Views
    112

    "Hello" is a string constant because it is a...

    "Hello" is a string constant because it is a string constant by definition. Likewise, in this program below, 123 is an integer constant because it is an integer constant by definition, no const...
  7. Replies
    4
    Views
    112

    "Hello" is a string constant, so it exists...

    "Hello" is a string constant, so it exists independently of the pointer.
  8. Replies
    5
    Views
    187

    The simple answer is that you're looking at the...

    The simple answer is that you're looking at the effects of undefined behaviour because accessing an array out of bounds is undefined behaviour. Going deeper, it could be that you were modifying other...
  9. Replies
    2
    Views
    64

    You need to call the function through the...

    You need to call the function through the function pointer:

    (*execute)();
    It should also be possible to omit the explicit dereference as a form of syntactic sugar:

    execute();
  10. Replies
    5
    Views
    187

    Your idea of creating a new dynamic array and...

    Your idea of creating a new dynamic array and copying over the old one to it each time you add a grade is rather expensive: instead of taking amortised constant time, addGrade will take linear time,...
  11. Replies
    43
    Views
    650

    Think about picking one of four restaurants to...

    Think about picking one of four restaurants to eat at for lunch using a single roll of a six-sided die: if you use the entire range of the die using modulo, then two of the restaurants will be twice...
  12. Replies
    43
    Views
    650

    The code desperately needs to be formatted...

    The code desperately needs to be formatted properly and use descriptive variable names where appropriate, and possibly broken up into smaller functions that do one thing and do it well.

    But more...
  13. * moved to Tech Board *

    * moved to Tech Board *
  14. After you replace "class" with "struct", it's...

    After you replace "class" with "struct", it's even simpler because friendship, references, and parents don't exist in C, and you don't have to worry about the case where a member function that is...
  15. Perhaps you meant to say that you're supposed to...

    Perhaps you meant to say that you're supposed to print a sequence, presumably of variable length? If so, one simple solution is to save the initial number in a separate variable, then after using the...
  16. Replies
    9
    Views
    163

    If you're having difficulty understanding K&R,...

    If you're having difficulty understanding K&R, then put it aside for now and reach for a beginner's introductory book rather than an experienced programmer's introductory book.


    What does the...
  17. Replies
    9
    Views
    163

    The pointer is named v. C programmers often...

    The pointer is named v.


    C programmers often loosely use the word "struct" or "structure" to mean an object of struct type. In your example, there is no such object. struct X refers to the type,...
  18. Replies
    9
    Views
    163

    You can find such examples in any good...

    You can find such examples in any good introductory C textbook.

    Nonetheless, here is an example:

    struct X
    {
    int a;
    float b;
    };
    Then using the notation you used in post #1:
  19. Replies
    9
    Views
    163

    A struct type is a type that can be used to group...

    A struct type is a type that can be used to group objects of various types together into a single object.
  20. It doesn't. Take a look at the GCC documentation...

    It doesn't. Take a look at the GCC documentation for Options for Linking. You will see this section:

    So, -lm would link to the library named m (or in context, libm), which should be contained in a...
  21. Replies
    3
    Views
    144

    What happens is that the standard input stream...

    What happens is that the standard input stream enters a failed state. You need to clear the state and remove the bad input.

    Instead of this, another option when dealing with such line-based input...
  22. Yes. In general, a pointer to some type X cannot...

    Yes. In general, a pointer to some type X cannot store values of type X. It can only store addresses of objects of type X (or be a null pointer), so if you want to store a value of type X using such...
  23. You forgot to set the pointer to point to an...

    You forgot to set the pointer to point to an object, so what happens is that the pointer to garbage (or which happens to be a null pointer by chance) is dereferenced, possibly leading to a...
  24. Replies
    5
    Views
    131

    That's because you're trying to treat dict[j] as...

    That's because you're trying to treat dict[j] as a pointer when it is an object. Write dict[j].name instead.


    C only has pass by value semantics. Pass by reference can still be done through a...
  25. Replies
    5
    Views
    131

    You have an array of DICTIONARY objects, so when...

    You have an array of DICTIONARY objects, so when you pass it as an argument, it is converted to a pointer to its first element. Hence, you should declare your function like this:

    uint32_t...
Results 1 to 25 of 500
Page 1 of 20 1 2 3 4