answersLogoWhite

0

What are c plus plus statements?

Updated: 8/11/2023
User Avatar

Wiki User

10y ago

Best Answer

Statements are how we tell the compiler what we want our program to do. In other words, they are the instructions written in C++ code. A statement may be a simple instruction to invoke a function call, such as:

foo();

Or to perform an operation, such as adding two integers:

x+=y;

Note that all statements end with a semi-colon.

We can also group individual statements together to form a compound statement. For instance, when we use an if statement to evaluate a condition, we might want more than one statement to execute if the condition were true. We use curly braces to create a compound statement:

if (x==42)

{

for(int i=0; i<100; ++i)

std::cout<<i<<std::endl;

foo();

}

In the above example, if x were 42, then we'd print the number 0 to 99 and then call foo(). If x were not 42, then we'd skip over the entire compound statement and execute the next statement instead.

Compound statements may also be nested. In the above example, for instance, the for loop might contain a compound statement:

if (x==42)

{

for(int i=0; i<100; ++i)

{

std::cout<<i<<std::endl;

foo(i);

}

}

In this case, we print the value 0 and then call foo(0) on the first iteration of the loop, then print 1 and call foo(1), and so on. But since the for loop constitutes the entire compound of the if statement, we can eliminate the outer set of braces completely:

if (x==42)

for(int i=0; i<100; ++i)

{

std::cout<<i<<std::endl;

foo(i);

}

We can also create compound statements using commas to separate the individual statements. For instance, when we delete a pointer we will typically nullify the pointer straight away. Like so:

if (p)

delete (p), p=NULL;

The above is simply a shorthand for the following compound statement:

if(p)

{

delete(p);

p=NULL;

}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

For example: <expression>, <statement-block>, <null-statement>, switch, if, while, for, return, break, continue, try, catch...

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are c plus plus statements?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What c plus plus statements assign x the value 12?

x = 12;


What is the character used at the end of executable statements in C plus plus?

The semi-colon converts a C++ expression into a statement.


What are the conditional statement of turbo c plus plus dos based?

Statements that check an expression then may or may not execute a statement or group of statements depending on the result of the condition.


What are unconditional statements in c plus plus?

Unconditional statements are statements that are invoked unconditionally. Conditional statements have a controlling expression, while unconditional statements do not. For example: void f (bool b) { if (b==true) do_something(); // conditional statement (controlled by the expression b==true) do_something_else(); // unconditional (executes regardless of b's value) }


What is the notation used to place block of statements in a looping structure in C plus plus?

for( ; ; ) { statement_block; } while( conditional_expression ) { statement_block; } do { statement_block; }while( conditional_expression )

Related questions

Control statement in c plus plus?

Control statements are statements that alter the flow of execution according to the evaluation of an expression (the condition). The C++ control statements are ifstatements, switch statements and the tertiary conditional operator, ?:.


What is the difference between statements in c plus plus charconstp and char constp?

There is no difference. Both statements are invalid.


What c plus plus statements assign x the value 12?

x = 12;


What is the character used at the end of executable statements in C plus plus?

The semi-colon converts a C++ expression into a statement.


How to make decision making statements in c plus plus?

Decision making statements make use of conditional expressions. In C++ there are three possibilities: if/else, switch/case and the ternary operator (?:).


Explain control instructions in c plus plus?

Control instructions are instructions that alter the flow of execution. In C++ this include if, if-else statements, switch-case statements and the conditional ternary operator (?:), as well as loop structures (for, while, do-while) and procedural goto statements.


What are the conditional statement of turbo c plus plus dos based?

Statements that check an expression then may or may not execute a statement or group of statements depending on the result of the condition.


Looping statement in c plus plus?

There are several 'looping' statements in C++. They are:while () { }do { } while () ;for (index-start, index-end; index increment/decrement) { }They are used to repetitively execute statements as long as the statement(s) controlling the loop are true.


What are unconditional statements in c plus plus?

Unconditional statements are statements that are invoked unconditionally. Conditional statements have a controlling expression, while unconditional statements do not. For example: void f (bool b) { if (b==true) do_something(); // conditional statement (controlled by the expression b==true) do_something_else(); // unconditional (executes regardless of b's value) }


What is the notation used to place block of statements in a looping structure in C plus plus?

for( ; ; ) { statement_block; } while( conditional_expression ) { statement_block; } do { statement_block; }while( conditional_expression )


How do you terminate statements in C?

All statements must be terminated with a semi-colon in C.


How can you get c and c plus plus output statements to work together?

The C and C++ library routines for output might, or might not, include use of different buffers. If they are the same buffer (unlikely) then you can simply intermix the techniques. If they are not the same buffer then you need to do a flush sequence between techniques.