Help with simple c++

Hi! Could someone help me explain the first piece of code. What´s going on in that code and then theres a second block of codes with some mistakes in it.
Would really appreciate it. thanks! :)

1
2
3
4
5
6
7
8
9
10
11
12
13
  #include <iostream>
using namespace std;
int main(){
 int i=1;
 int ii=11;
 int o=2;
 int *oo=&o;
 i--;
 --i;
 ii=i+ii+*oo;
 *oo=*oo+*oo+o;
 cout<<i<<endl<<ii<<endl<<o<<endl<<*oo<<endl;
}



Find 5 mistakes.....
1
2
3
4
5
6
7
8
9
10
#include <sodastream>
using namespace std;
int main(){
 while(int i=0; i<2; i++){
 cout<< KanonKula <<endl;
 )
 int a=2
 if(a==2)
 a=3;
}
You have access to a compiler and debugger. Run the program, and see if you can follow its behavior.
- Your C++ compiler will identify every syntax error and point you straight to it;
- Your source-level debugger will allow you to run the code statement-by-statement, and examine the values of variables after each statement.


Sometimes the compiler can become confused by an incorrect input - so the first error message is typically the most valuable and reliable bit of information. Therefore, when working on finding the errors in the second program, you will need to feed the source code to the compiler, identify and repair the first error the compiler finds, then repeat.
Sheesh!, alphabet soup belongs here -> https://www.ioccc.org/
1
2
3
4
 int i=1;
 int ii=11;
 int o=2;
 int *oo=&o;

Well the first step in your analysis would be to rename those AWFUL variable names to be something meaningful. Whoever set that isn't teaching you how to program.

Maybe
1
2
3
4
 int small=1;
 int large=11;
 int scale =2;
 int *scaleptr = &scale;

At least you might have a chance to figure out what's going on.

Rename them again if it helps.



Topic archived. No new replies allowed.