Difference between "C structure" and "C++ structure".

Showing Answers 1 - 22 of 22 Answers


  • Jul 20th, 2005

The defination of the structure in C is limited to within the module and cannot be initialized outside its scope. Where as in C++ you can initialize the objects anywhere within the boundaries of the project.


  • Jul 23rd, 2005

The on more deference is , in C++ structure can have methods(procedures) but C can note have methodes in structure


  • Aug 25th, 2005

By default C structure are Public whil C++ structure are private 


  • Dec 31st, 2005

c can have methods in structures dude..

  Was this answer useful?  Yes


  • Feb 26th, 2006

C does not support Methods inside structure.

Reason :

║#include <stdio.h>
║#include <conio.h>

║struct temp
║  int a;
║  get_data()
║  {

      printf("Enter value of a : ");
║    scanf("%d",&a);
║  }

║void main()
║   T.get_data();

saved  file as ".c" file
Error : Function May not be part of structure of Union
and same code will run if you save file as ".cpp"

Yashwant S pinge

  • Mar 27th, 2006

Since , bydefault, C and C++ structure members are public.In C, you can declare structure as struct A a;But not A a(which is possible in C++);


  • Jun 4th, 2006

I cant able understand your answer. Please tell what method difference in C and C++. Please explain briefly. Please Reply to my ID



  Was this answer useful?  Yes


  • Jun 26th, 2006

Mr Rohan,

I actually tried saving the code you have given with extention .c and .cpp and it runs for both... So, I dont understand how you are saying that methods are possible only in the case of structures of cpp... could you clarify my query?

Thank you

  Was this answer useful?  Yes

Siddharth Nimkar

  • Aug 25th, 2006

Turbo C will allow you to run the above code with .c extension.But try running the code in Dev C++ (this is another IDE) this will give you error. I guess Dev C++ uses "gcc"


  • Oct 4th, 2006

C++ structures are also by default public

Aneena Mathew

  • Jan 4th, 2007

In C all the variables in the structure are public by default,we cannot declare a variable private or protected.but in c++ though all the variables in the structure are public we can declare variables as private or protect. 

Sadasivan Arun

  • Jan 4th, 2007

C structures and C++ structures differ mainly in the fact that object manipulation within each other is possible in C++ and not in C.  It means that with the help of operator overloading in C++ its possible for addition and other such operations involving arithmatic operators which is not possible in C as it does not support polymorphism.

  Was this answer useful?  Yes

Binu Sam

  • Apr 21st, 2007

  •  C Structures are by default Private.
  •  C++ Structures are  by default public

These are the main difference between C Structures and C++ Structures

  Was this answer useful?  Yes


  • Jul 10th, 2007

I also excuted the code which was given by one of our friend.
I got only one difference (public & private).

and in Many Books, they wrote that C dont have methods.
Can you give brief about this topic.

  Was this answer useful?  Yes

aanchal agarwal

  • Jul 29th, 2007

both in c and c++ data members are public by default. to make the data members private in c++, we must use the keyword private .

C structures does not supports inheritance. Also, all members are public and the keywords public, private and protected are not allowed to be used. C structures can only contain data members but no member functions.

  Was this answer useful?  Yes

The basic difference in C and C++ structures is :
1) In C , default access for structure members is public
2) In C++ , defaulot access for structres is private

  Was this answer useful?  Yes

There are two different things / comparisons.

1) Structs in C v/s C++    AND 2) Struct v/s Class in C++

1) struct in C & struct in C++ have two main difference that
A) struct in C can not have direct functions / methods inside struct definition (but it still can have methods in form of Function Pointers).
While in struct in C++, can have functions / methods inside struct definition like classes.
B) in C, an object of struct is created as struct A a; while in C++, it can be directly created as A a;.

2) struct in C++ & class in C++, have a difference of just default access, i.e. members of struct in C++ have PUBLIC access, if not specified WHILE members of class in C++ will have PRIVATE access if not specified.

  Was this answer useful?  Yes


  • Jul 29th, 2011

In C, there is no access specifiers. No need to mention public.

C struct only contains data and C++ struct can have data as well as methods. All OOPs concepts can implies to C++ struct.

The only one difference between class and C++ struct is by default class is private and C++ structure is public.

  Was this answer useful?  Yes


  • Aug 11th, 2011

1.in c we can specify the structure in the main() function only and by default it as public.

2.in c++ we can specify the structure in the classes also and we can set it as private or protected.

3.in c we have the concept of inheritance to inherit the methods that were specified in the structure but in c it can't.

  Was this answer useful?  Yes


  • Aug 22nd, 2011

structures are also public in c..... thats why we can use it in main function

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions