Difference between c structure and c++ structure

R

raghunandan_1081

Hi guys, can you please tell me what is the Difference between c
structure and c++ structure
 
O

opalpa

None of the eight questions in page under FAQ link match question
asked, in my opinion. I suppose you could interpret the OP's question
to be a comparison between C struct and C++ class, but I read OP's
question as a comparison between C struct and C++ struct.

One difference between C struct and C++ struct is that C++ struct can
have methods inside. Another difference is that parts of C++ struct
can be "hidden" by being made private.

Opalinski
http://www.geocities.com/opalpaweb
(e-mail address removed)
 
K

Kai-Uwe Bux

None of the eight questions in page under FAQ link match question
asked, in my opinion. I suppose you could interpret the OP's question
to be a comparison between C struct and C++ class, but I read OP's
question as a comparison between C struct and C++ struct.

Since the only difference between a C++ struct and a C++ class is the
default access (public for struct, private for class), the explanation in
"what is a class" together with "what's the difference between the keywords
struct and class" should answer the question of the OP (assuming the OP
knows C structs).
One difference between C struct and C++ struct is that C++ struct can
have methods inside. Another difference is that parts of C++ struct
can be "hidden" by being made private.


Best

Kai-Uwe Bux
 
O

opalpa

Since the only difference between a C++ struct and a C++ class is the
default access (public for struct, private for class), the explanation in
"what is a class" together with "what's the difference between the keywords
struct and class" should answer the question of the OP (assuming the OP
knows C structs).

I agree. Good point. With the above directions OP will be fine.

Opalinski
(e-mail address removed)
http://www.geocities.com/opalpaweb/
 
O

osmium

Hi guys, can you please tell me what is the Difference between c
structure and c++ structure

The syntax for using a struct is different in C than C++.

In C++ struct is a type, and can be referred to much like an int. Not so in
C.
 
B

Bob Hairgrove

The syntax for using a struct is different in C than C++.

In C++ struct is a type, and can be referred to much like an int. Not so in
C.

Actually it is also a type, except that you have to prefix every use
of the name with the keyword "struct" unless you declare it as a
typedef.

As you say, of course, the syntax is different, but types in C have
different semantics than in C++ anyway.
 
G

Gimmmo

Actually it is also a type, except that you have to prefix every use
of the name with the keyword "struct" unless you declare it as a
typedef.

struct A {
char x;
int y;
};

struct A A1;

struct A A2;
A2.x = 1;
A2.y = 600;

In C:
A1 = A2; <--- can do?
If i'm not wrong, must use memcpy() byte by byte.

In C++:
A1 = A2; <--- can do?


Rgds.
 
Joined
May 23, 2011
Messages
1
Reaction score
0
In C++ it is allowed to define functions as part of a struct where as you can not define function in C structures.
 
Joined
Nov 11, 2011
Messages
1
Reaction score
0
Hi guys, can you please tell me what is the Difference between c
structure and c++ structure

1>In C: structure is just data container.

In C++: structure is almost identical to class. There is only one difference between structure and class in C++ : data members in structure are by default public, and in class they are by default private.

2>In c structure
~we can not have access specifiers
~can not have functions
But in c++
~we can specify data as a public , private and protected

3> we can add the opp concept to stuct in c++ but the reverse is not true.


thanks & regards
{LAL}:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top