165k views
5 votes
What will the following code display?

int number = 6;
cout << ++number << endl;




1. 0

2. 5

3. 7

4. 6

1 Answer

1 vote

Answer:

7

Step-by-step explanation:

The operator '++number' is called the pre increment operator which is used to increment the value by 1 first and then assign.

for example:

int n = 10;

b = ++n;

here, it increase the value of 10 first then assign to b. hence, b assign the value 11.

similarly, in the question:

int number = 6;

after that, the pre increment operator increase the value by one and then assign to number.

it means number assign the value 7 and finally print the value.

Therefore, the answer is 7.

User LauraTheExplorer
by
6.0k points