Linear Structure



The linear structure is represented by instructions that execute in the same way every time the program (or program segment) is run, regardless of the values of the variables being used.


Expression Statement

The expression statement is the most frequently used type of statement in a C++ program. An expression becomes a statement if it is followed by ";".

Examples:

x = 2;
x++;
cout << x;

Declaration Statement

A declaration statement can declare identifiers of a certain type. Identifiers can be variables, but as we will see later, they can also be functions.

Examples:

int x, y , z;
double a;

Compound Statement

The compound statement, or block, is a grouping of declarations and statements enclosed between curly braces {}. They were introduced to use multiple statements where the syntax requires a single statement. The compound statement or block is syntactically equivalent to a single statement. The block also determines a scope for the identifiers. More precisely, identifiers declared in a block will be removed when the block is terminated.
After the closing curly brace } do not write ";"!

Example:

#include 
using namespace std;
int main()
{
      int x = 5;
      {
          int x = 7;
          cout << x << endl; // 7 will be displayed
      }
      cout << x << endl; // 5 will be displayed
      return 0;
}

Return Statement

A return statement allows exiting a function and passing control back to the caller of the function. A function can return values to its caller via a return statement.

Example:

return;

Or


return expression;

In the first case, the returned value is undefined. In the second case, the value of the expression is returned to the caller of the function.


Empty Statement

In certain situations, the C++ language syntax requires a statement at a certain point in the program, but the program logic does not. This is where the empty statement comes in, with the following syntax:


;

When the empty statement is encountered, no action will be taken.


Color Contrast

Text Size

Text Spacing

Reading Aids


In this section you can generate a summary of the page content using AI! Feel free to use the button below whenever you are in a hurry and don't have time to learn everything!


Summary

In this section you can ask our expert robot anything related to the questions you encountered during the lessons! Feel free to use the button below whenever you need additional explanations!


Chatbot