473,473 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

difference b/w structures in c and c++

19 New Member
can anybody tell me the difference between structures in c and structures in
c++?
Jan 29 '07 #1
3 7626
horace1
1,510 Recognized Expert Top Contributor
can anybody tell me the difference between structures in c and structures in
c++?
in C and C++ you can create composite data types with struct
Expand|Select|Wrap|Line Numbers
  1. struct Student {                       
  2.                 char name[20];            // student name 
  3.                 int age;                   // student age 
  4.                 int course_code;        // institutions course code 
  5.                 int course_year;        // year of course 
  6.                 };
  7.  
a struct can only contain data members.
In C++ the aggregate type class (an extension of the idea of struct) enables users to define their own types each of which is an encapsulation of:
(a) data members (fundamental types and derived types, e.g. arrays, structures, classes, etc.),
and (b) function and operator members which operate upon the data.
Jan 29 '07 #2
r035198x
13,262 MVP
can anybody tell me the difference between structures in c and structures in
c++?
You have to use typedef in C or else you define your structures using
struct MyStructure s; but in C++ you can jusy say MyStructure s;
Jan 29 '07 #3
LSB
8 New Member
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.

Thanks.
Jan 29 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: kazack | last post by:
Hi all it's me again with another question as I got further in my book. The chapter I am in covers structres, abstract data and classes. I only read through to the end of the coverage on...
22
by: Ook | last post by:
We have had a discussion on the differences between a class and a structure, and no one is in agreement. As I understand it, a structure defaults to public, a class defaults to private. There are...
4
by: Thomas Paul Diffenbach | last post by:
Can anyone point me to an open source library of /statically allocated/ data structures? I'm writing some code that would benefit from trees, preferably self balancing, but on an embedded system...
6
by: nick | last post by:
I have tried finding an answer to this, but most people just explain classes as a more modular way to program. It seems to me that (forgetting OO programming which I don't quite understand) the...
5
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but...
6
by: Ken Allen | last post by:
OK, I admit that I have been programming since before C++ was invented, and I have developed more than my share of assembly language systems, and even contributed to operating system and compiler...
14
by: pmclinn | last post by:
I've noticed that many programmers use classes to store data about such things like: Class Customers .....Phone ....ID ....Address End Class....
4
by: zacks | last post by:
A common programming technique I use in VB is making a collection of structures. But if Option Strict is on (which I would prefer), the .Add that adds the structure to the collection is flagged...
1
by: jehugaleahsa | last post by:
Hello: I am experiencing performance related issues when my custom data structures work with value types. I use generics to prevent boxing wherever I can. For instance, I use IEqualityComparer,...
4
by: Google Groups | last post by:
If i take two structures with same members then,why cann't i compare those two structures?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.