answersLogoWhite

0

There is no single structure to a C++ program. C++ is multi-paradigm and allows programmers to use any combination of C-style programming, object-oriented programming and template metaprogramming using a mixture of primitive built-in types, standard library types and user-defined types.

User Avatar

Wiki User

8y ago

Still curious? Ask our experts.

Chat with our AI personalities

BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake
FranFran
I've made my fair share of mistakes, and if I can help you avoid a few, I'd sure like to try.
Chat with Fran
ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
More answers

Structured programming is best explained by understanding procedural programming first. Procedural programming makes prevalent use of goto statements and makes no use of function calls. In other words, the entire program is written as a single main function, that executes from top to bottom. When a goto is encountered, execution jumps to the appropriate label and continues from there. Thus the execution path is difficult to follow, resulting in "spaghetti code" that is difficult to read and maintain.

Structured programming addresses this problem through the use of procedure calls that allow code to be broken down into small procedures or subroutines that can be called as and when required. Unlike a goto, a procedure call returns to the point of the call and can return values to the caller. Structured programming also makes use of structured loops, such as while, do-while and for, as well as more complex structures such as switch statements. These structures make programs much easier to read and maintain. Both C and C++ allow any combination of procedural and structured programming, while C++ also allows object-oriented programming, which improves structured programming through the use of self-contained objects that encapsulate data and the methods that operate upon that data, thus limiting the scope of the data and ensuring more robust code.

User Avatar

Wiki User

11y ago
User Avatar

Programs in C are structured as one or more functions, with main() being a required function (the entry point of the application, which must return an integer). Functions may call other functions. All functions apart from main() must be declared before they are called, either by including the appropriate header file, or by explicitly declaring the function prototype prior to use. The declaration may include the definition, however declarations and definitions are usually separated. C also permits user-defined types, including structures, all of which have public access unless defined locally within a function or statement block. Structures can also contain functions, thus C is considered a structured programming language, although it is primarily a procedural language.

C++ is derived from C but extends the language to provide object-oriented programming concepts (OOP). The syntax is largely the same, with minor differences to cater for OOP compliance. C++ permits procedural and structured programming concepts to be mixed with OOP concepts. Classes in C++ are much like structures, but are private by default. This allows data and the methods that act upon that data to be encapsulated such that data is hidden by a controlling interface, parts of which may be declared publicly accessible. Through inheritance and polymorphism, new classes can be derived from existing classes, minimising code duplication. The same is also true of structures, but without the safeguards that classes provide.

User Avatar

Wiki User

12y ago
User Avatar

Add your answer:

Earn +20 pts
Q: What is the program structure of C language and C plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp