Search

Sponsored Links

Meta

Categories

Archives

Recent Posts

RSS Feeds

13
Apr

What is allowed in C, but not in C++?

Related Blog Items

    Following are few differece in C and C++.  Few of these are allowed in
C++, but with a different meaning; while some are illegal.

1.  sizeof (’1′) == sizeof (int) in C; but it is sizeof (char) in C++.

2.  You generally should NOT use *alloc()/free() in C++; but they are the
    only such functions in C.  Use new and delete combination, instead.

3.  Functions need not be prototyped in C; but, it’s a must in C++.
    Peter Nilsson says:

       "C99 changed from C90 in that named functions must be _declared_ prior
        to usage, but there is still no requirement that the function be
        prototyped. [The exception being variadic functions like printf,
        which have always required prototypes in standard C.]"

4.  struct a {
        struct b {
            int a;
        };
    };

    struct b b;         /* allowed in C; but, not in C++ */

5.  const int b = 1;    /* allowed in C and C++ */
    const int a;        /* allowed in C, but not in C++ */

6.  Global variables can be defined more than once in C, not in C++.
    int a;              /* both in C and C++ */
    int a = 10;         /* legal in C; illegal in C++ */

7.  const a;            /* allowed in C; illegal in C++ */

    This is equivalent to const int a; in C.

8.  char s[7] = "vijoeyz";  /* error in C++, but allowed in C */

9.  K&R style function definitions are not allowed in C++.  Example:

    void mango ( a )
    int a;
    {   …  }

Popularity: 6%

You need to log on to convert this article into PDF


Related Blog Items

No Comments

No comments yet.

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image