answersLogoWhite

0

What are constructs in c plus plus?

Updated: 8/21/2019
User Avatar

Wiki User

10y ago

Best Answer

C++ has 4 basic constructs:

  1. Sequential
  2. Selection
  3. Repetition
  4. Routine invocation

Sequential Construct

Sequential constructs determine which instruction will be executed next. In most languages the default will be the instruction that immediately follows the current instruction. However, most languages include jump statements which can be used to alter the execution sequence. In C++, jump statements employ the goto, return, break and continue keywords.

Selection Construct

Selection constructs include if-else and case statements (some languages also employ pattern matching, but not C++). These are primarily used to determine which statement will be executed from a list of alternate statements. If-else statements allow us to select one statement from a maximum of two statements based upon the evaluation of an expression. We can also nest if-else statements to cater for additional alternates. However, if the expression to be evaluated is the same for each alternate then it is usually more succinct to use a case construct rather than repeatedly re-evaluating the same expression. In C++, case statements may include goto, return and break statements to determine where an alternate ends, thus allowing execution to fall-through more than one case where desired.

Repetition Construct

Repetition constructs involve loop statements, such as for, while and do-while, as well as procedural loops involving goto statements, where a simple or compound statement may be iterated a fixed number of times or a variable number of times. All loops must have at least one exit point, which can either be pretest or posttest. An exit point is a conditional expression that evaluates true or false. So long as the condition remains true, the body of the loop will continue iterate. With pretest loops, the condition is evaluated before each iteration while posttest loops evaluate the condition at the end of each iteration. The only real difference is that posttest is guaranteed to iterate at least once whereas pretest may not iterate at all. In C++, for and while loops are pretest and do-while is posttest. Procedural goto loops are always posttest. Although all arguments in a for loop are optional, the conditional expression is always true unless an expression is explicitly stated. Where a condition is always true, the loop is said to be variable length and infinite. However, in order to be a valid loop, the body of an infinite loop must contain at least once exit condition (which must include a break, return or goto statement that exits the loop). C++ loops may also use the continue keyword to start a new iteration if the condition (whether pretest or postest) remains true.

Routine Invocation Construct

Routine invocation construct describes procedure calls (or function calls). Unlike a goto statement that branches off to another section of code, a procedure call returns to the point of the call after invoking the procedure. To achieve this, C++ employs the call stack, pushing the return address onto the stack before invoking the named procedure. When the procedure has completed its task, the return address is popped from the stack and control is returned to that address. The call stack can also be used to pass arguments to and from the procedure, as well as returning a single value from the procedure (the return value). This mechanism allows procedures to call other procedures without losing track of the return paths. Procedures may also call themselves, recursively, using the call stack to maintain the variable state of each instance of the procedure.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are constructs in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Enumerate the types of selection constructs in c plus plus?

Selection constructs in C++if...elseswitch/caseconditional ternary operator (?:)


What are decision making constructs in c?

if else and switch case satements


What is an object in c?

C does not contain any built in constructs for object oriented programming. Methods and Data are generally not stored in an object structure in c.


What is b plus b plus b plus c plus c plus c plus c?

b+b+b+c+c+c+c =3b+4c


What is c plus c plus 2c plus c plus c equal?

c + c + 2c + c + c = 6c


B plus b plus b plus c plus c plus c plus c equals?

b + b + b + c + c + c + c = 3b + 4c


Is c plus plus in CBSE class 10?

No. Information technology in central board secondary education doesn't appear to extend much beyond simple HTML/XML constructs. No real surprise there -- C++ is usually taught at college/university level -- but I would have expected some language theory at least, even if only at BASIC level. But it appears not.


Symplify c plus c plus c plus c?

4c


What is c plus c plus c plus c plus c?

c + c + c + c + c = 5 * c.


Primary and secondary key in c and c plus plus?

There are no "primary and secondary keys" in c and c plus plus.


What is c plus C plus C answer in algebra?

3c


What is the different between turbo c plus plus and unix c plus plus?

There is no such thing as 'unix C++'.