I am not able to understand the following points in regard to difference between C and C++,

1.The comma operator can result in an "l-value" (a quantity that can be used for the left-hand side of an assignment) in C++, but not in C.
2.Enumeration constants (enum values) are always of type int in C, whereas they are distinct types in C++ and may have size different from that of int.
3.C++ identifiers are not allowed to contain two or more consecutive underscores in any position. C identifiers are not allowed to start with two or more consecutive underscores, but may contain them in other positions.
4.In both C and C++ one can define nested struct types, but the scope is interpreted differently (in C++, a nested struct is defined only within the scope/namespace of the outer struct).
5.C allows struct, union, and enum types to be declared in function prototypes, whereas C++ does not.
6.A struct, union, or enum declaration in C++ is a first class type, while in C it is not.

Can anyone explain , some if not all, with examples.Thanks in advance

1) The following compiles as C++, but not in C:

#include <stdio.h>

int main ( void )
{
  int a = 0;
  int b = 0;

  (a, b) = 10;

  return 0;
}

2) The short answer is that an enum constant in C is an integer type, but in C++ (for static type checking) the constant matches the type of the enum:

#include <iostream>
#include <typeinfo>

enum foo { FOO, BAR };

int main()
{
  std::cout<< typeid ( foo ).name() <<'\n';
}

3) This is kind of tricky. Both C and C++ will allow you to use two consecutive underscores anywhere in your identifiers. The restriction is actually there as a guideline to keep mortal programmers from stepping on the toes of the implementation. Implementors typically use leading underscores and double underscores to avoid potential naming conflicts with the standard library and client code. The underscore rules for C and C++ are there to reserve certain identifier formats for the implementation.

4) The following compiles as C, but not C++:

#include <stdio.h>

struct foo {
  struct bar {
    int b;
  } x;
};

int main ( void )
{
  struct foo x;
  struct bar y;

  return 0;
}

5) The following compiles as C, but not as C++:

void foo ( struct bar { int a; } x );

int main ( void )
{
  return 0;
}

6) This is pretty self explanatory. You should do some research on first class types. ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.