Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
J

jfbode1029

@jfbode1029
About
Posts
6
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Tell me about the c programming languages
    J jfbode1029

    C Programming - Wikibooks, open books for an open world[^]

    C / C++ / MFC

  • How cin.get() works in loop ?
    J jfbode1029

    cin.get() does not read individual keystrokes -- the input is buffered by the terminal until you hit Enter, then all of the input is sent to the program at once. To read individual keystrokes, you'll have to rely on a third-party tool like GNU's ncurses library.

    C / C++ / MFC question

  • Why does most C/C++ developer prefers char *c instead of char* c?
    J jfbode1029

    There are indeed pointer types, but there are no pointer type specifiers. The pointer-ness of something is specified by a combination of the type specifier(s) and the declarator. For a pointer like

    char *p;

    the type of p is "pointer to char" or char *, but that type is obtained by the combination of the type specifier char and the pointer declarator *p. Sure, you can write it as char* p;, but it will be parsed as char (*p);. Something like

    T *p1, *p2, *p3;

    should be perfectly understandable to anyone who understands C and C++ declaration syntax, but nobody does because it's not taught properly for some bizarre reason. It's such a fundamental part of the language, but it's invariably glossed over in every introductory text so as not to scare off beginners. So people inevitably bluescreen the first time they see something like a pointer to an array or a pointer to a function because the simplistic-to-the-point-of-being-wrong version of C declaration syntax they were taught doesn't account for it. Yes, pointers are scary and difficult to understand at first. They're also a fundamental part of C programming (less so C++, but still important). C (and C++) declaration syntax needs to be taught properly and completely. But since it isn't, we need to come up with a bunch of coding standards to make up for it. So, no more than one declaration per line, because it's too hard to explain how char* a, b; really works. Once you understand the rules, pointer declarations (including pointers to arrays, pointers to functions, pointers to arrays of functions returning pointers to arrays of pointers to int) make perfect sense. But apparently nobody understands the rules, so the language looks arbitrary and capricious.

    The Lounge question c++

  • Return a local 2d Array
    J jfbode1029

    The return type for getArray needs to be int (*getArray())[COL];. An expression of type T [M][N] decays to type T (*)[N], not T **. So your code needs to be

    int main()
    {
    int (*ptr)[N];
    int (*getArray())[N];
    ...
    }

    int (*getArray())[N]
    {
    ...
    return tab;
    }

    C / C++ / MFC data-structures tutorial question

  • i would like to be a programmer
    J jfbode1029

    Programming is more than just writing code - it's about solving problems with code. You'll need to develop analysis and troubleshooting skills in addition to straight coding skills. Having said that, the best way to learn how to write code is to actually write code. You could start by looking at Codecademy. It's free, it's all done in the browser (so you don't have to set up a development environment on your local machine), and they cover a useful range of languages. I haven't used it much myself, so I can't comment on the quality of the instruction. It may be good, it may be awful. Depends on what you want to learn.

    C / C++ / MFC question

  • Why does most C/C++ developer prefers char *c instead of char* c?
    J jfbode1029

    Because that's how both the C and C++ grammars work. The asterisk binds to the thing being declared, not the type. A declaration like

    int* a, b;

    is parsed as

    int (*a), b;

    Declarations in C (and simple declarations in C++) are a sequence of declaration specifiers followed by one or more (optionally initialized) declarators. The declarator is what specifies the name along with the the pointer-ness, array-ness, and/or function-ness of the thing being declared. Given a sequence of declaration specifiers D1, then the following are all true:

    D *p; // p is a pointer to D
    D a[N]; // a is an array of D
    D f(); // f is a function returning D

    D *ap[N]; // ap is an array of pointers to D
    D *fp(); // fp is a function returning a pointer to D

    D (*pa)[N]; // pa is a pointer to an array of D
    D (*pf)(); // pf is a pointer to a function returning D

    D (*fpa())[N]; // fpa is a function that returns a pointer to an array of D
    D (*apf[N])(); // apf is an array of pointers to functions returning D

    // even more complex combinations are possible!!!

    The things following D are the declarators. *p is a declarator, as is a[N], as is *ap[N], as is (*pa)[N]. Since both [] and () operators have higher precedence than unary *, an expression like *a[N] parses as *(a[N]). To declare a pointer to an array or a pointer to a function, you must explicitly group the * operator with the thing that points to the array or function. This is why the common convention (at least among C programmers) is char *c; and not char* c;. I understand where the type* name and type& name conventions came from in C++, and when I write C++ I follow that convention. But I feel dirty every time I do it.


    1. Declaration specifiers include storage class specifiers like static, auto, and typedef, type specifiers like int, double, struct foo, and type qualifiers like const or volatile

    The Lounge question c++
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups