Вы находитесь на странице: 1из 5

Although there are differences between Structured programming and object oriented

programming, they are both useful to programmers.

[edit] Structured Programming


• Structured programming takes on the top-to-bottom approach.
• It splits the tasks into modular forms. This makes the program simpler and easier
to read with less lines and codes.
• This type of program accomplishes certain tasks for that a specific reason.
• For example, invoice printers use structured programming. This type has clear,
correct, precise descriptions.

[edit] Object Oriented Programming


• This type of programming uses sections in a program to perform certain tasks.
• It splits the program into objects that can be reused into other programs.
• They are small programs that can be used in other software.
• Each object or module has the data and the instruction of what to do with the data
in it. This can be reused in other software

Differences between structure and class in c++ :


1.Structure in c++ does not provide datahiding whereas class in c++ provides
datahiding.
2.Classes support polymorphism,whereas structure donot.
3.By default everything in structure is Public and everything in class is private,but u
can change it.
4.By default inheritance of structure is public and inheritance of class is private.

Reference (C++)
From Wikipedia, the free encyclopedia
Jump to:navigation, search

In the C++ programming language, a reference is a simple reference datatype that is less
powerful but safer than the pointer type inherited from C. The name C++ reference may
cause confusion, as in computer science a reference is a general concept datatype, with
pointers and C++ references being specific reference datatype implementations.

Contents
[hide]

• 1 Syntax and terminology


• 2 Relationship to pointers
• 3 Uses of references
• 4 ISO definition

• 5 External links

[edit] Syntax and terminology


The declaration of the form:

<Type> & <Name>

where <Type> is a type and <Name> is an identifier whose type is reference to <Type>.

Examples:

1. int A = 5;
2. int& rA = A;
3. extern int& rB;
4. int& foo ();
5. void bar (int& rP);
6. class MyClass { int& m_b; /* ... */ };
7. int funcX() { return 42 ; }; int (&xFunc)() = funcX;

Here, rA and rB are of type "reference to int", foo() is a function that returns a
reference to int, bar() is a function with a reference parameter, which is reference to
int, MyClass is a class with a member which is reference to int, funcX() is a function
that returns an int, xFunc() is an alias for funcX.

Types which are of kind "reference to <Type>" are sometimes called reference types.
Identifiers which are of reference type are called reference variables. To call them
variable, however, is in fact a misnomer, as we will see.

Difference between Pointers and Reference in C++


ADVERTISEMENT
Author

Recent Articles

Pointers and Reference looks similar but there are some difference between both of
them.

POINTER

1) Its not necessary to initialize the pointer at the time of declaration. Like

int a = 10;

int *P = &a; //It is not necessary

Another way is :

int a = 10;

int *P;
P = &a;

2) You can create the array of Pointer.

3) You can assign NULL to the pointer like

int *P = NULL; //Valid

4) You can use pointer to pointer.


REFERENCE

1) Its necessary to initialize the Reference at the time of declaration. Like

int &a = 10;

int &a; //Error here but not in case of Pointer.

2) You can not create the Array of reference.

3) You can not assign NULL to the reference like

int &a = NULL; //Error

4) You can not use reference to reference.

The difference between OOP and non-OOP

They are defined differently

A function is defined as a self-contained block of code. Each function name "fName"


must be unique within the application

They are defined differently

A function is defined as a self-contained block of code. Each function name "fName"


must be unique within the application

They have different numbers of working copies

A function does not have to be instantiated before it can be accessed, therefore only one
copy (or instance) is said to exist at any one time.

A class method can only be accessed after it has been instantiated into an object, and it is
possible to create multiple instances (objects) of the same class with different object
names.

They have different numbers of entry points

A function has only a single point of entry, and that is the function name itself.

An object has multiple points of entry, one for each method name.
They have different methods of maintaining state

A function by default does not have state, by which I mean that each
time that it is called it is treated as a fresh invocation and not a continuation of any
previous invocation.

An object does have state, by which I mean that each time an object's method is called it
acts upon the object's state as it was after the previous method call.

Вам также может понравиться