C++ Note
C++ Note
#include <iostream>
using namespace std;
int main()
{ int a;b; V.V.I
a=10;
b=(a);
cout<<b;
return 0;
}
Error: 'b' was not declared in this scope
#include <iostream>
using namespace std;
int main()
{ int a,b,c;
a=10;
b=20
cout<<a+1<<b+1;
return 0;
}
Answer:
Error : expected ‘ ; ‘before ‘cout’.
Warning: unused variable ‘c’
#include <iostream>
using namespace std;
int main()
{ int a,b;
a=10;
b=sqrt(a); work on header file <math.h>
cout<<b;
return 0;}
Answer:
Error: 'sqrt' was not declared in this scope
Output
If output variables has nothing to show actual results
then output for :
Data Output
Int 7208852
Char Null (nothing)
Float 1.0101e-38
Double 2.0513e-307
Example:
#include <iostream>
using namespace std;
int main()
{ int a; Output:2.0513e-307
double b;
a=10;
cout<<b; // nothing have for b to shown as output
return 0;
}
#include <iostream>
using namespace std;
int main ()
{ Output :6
int a=5; // initial value = 5
int b(2); // initial value = 2
int result; // initial value undetermined
a = a + 3;
result = a- b;
cout << result;
return 0;
}
#include <iostream>
using namespace std;
int main()
{ int a,b=10; Output:10.
a=10+2%2*3;
cout << a << endl;
return 0;
}
#include <iostream>
using namespace std;
int main ()
{
int a, b; // a:?, b:?
a = 10; // a:10, b:?
b = 4; // a:10, b:4
a = b; // a:4, b:4
b = 7; // a:4, b:7
cout << "a:";
cout << a; Output: a:4b:7
cout << " b:";
cout << b;
return 0;
}
#include <iostream>
using namespace std;
int main ()
{int a,b; // Output :66 // 57 //57
int c=5;
a=++c; //a=c++;//a=c++;
b=c++; //b=++c;//b=++c;
cout<<a;
cout<<b;
return 0;
}
#include <iostream>
using namespace std;
int main ()
{int a,b;
int c=1,d=2; // Output:2
a=++c; // 2
b=d++;
cout<<a<<"\n";
cout<<b;
return 0;
}
#include <iostream>
using namespace std;
int main()
{ int a=5,b=3,c=6;
if((a==5 && b>a ) && (b==3 || a>c)){
By :MUZAHED
ID:153092.
#include <iostream>
using namespace std;
int main()
{
cout<<"first loop\n";
for(int y = 5; y >0; y --)
{cout << y<< "\t"<< y; }
cout<<"\n\nsecond loop\n";
for(int z = 15; z < 10; z ++)
{cout << z << "\n"; }
return 0;
}
Output: first loop
5 54 43 32 21 1
second loop.
#include<iostream>
using namespace std;
int main ()
{
int i, j;
for(i=1;i<=3;i++) //outer loop start
{ cout<<"\ni is now\t"<<i;
for(j=1;j<=4;++j) //inner loop start
{
cout<<" j="<<j; //for 1 space.
} // inner loop end
} return 0; // outer loop end
}
Output:
i is now 1 j=1 j=2 j=3 j=4 // distance 1 space.
i is now 2 j=1 j=2 j=3 j=4
i is now 3 j=1 j=2 j=3 j=4