Find the output of following C++ programs
Program 1
codeaft.cpp
#include <iostream> using namespace std; int main() { float num1 = 7.7; double num2 = 7.7; if (num1 == num2) cout<<"Equal\n"; else cout<<"Unequal\n"; return 0; }
Show OutputOutput
codeaft@codeaft:~$ g++ codeaft.cpp
codeaft@codeaft:~$ ./a.out Unequal codeaft@codeaft:~$
Program 2
codeaft.cpp
#include <iostream> #include <iomanip> using namespace std; int main() { cout<<setprecision(52); double d = 3.14; cout<<d<<endl; return 0; }
Show OutputOutput
codeaft@codeaft:~$ g++ codeaft.cpp
codeaft@codeaft:~$ ./a.out 3.140000000000000124344978758017532527446746826171875 codeaft@codeaft:~$
Program 3
codeaft.cpp
#include <iostream> using namespace std; int main() { int x, y = 0; if ((x = y = 1) == 1) cout<<x<<" "<<y<<endl; return 0; }
Show OutputOutput
codeaft@codeaft:~$ g++ codeaft.cpp
codeaft@codeaft:~$ ./a.out 1 1 codeaft@codeaft:~$
Program 4
codeaft.cpp
#include <iostream> #include <cstring> using namespace std; int main() { cout<<strlen("Hello World\0\n")<<"\n"; }
Show OutputOutput
codeaft@codeaft:~$ g++ codeaft.cpp
codeaft@codeaft:~$ ./a.out 11 codeaft@codeaft:~$
Program 5
codeaft.cpp
#include <iostream> using namespace std; int main() { bool a = 0101; cout<<a<<endl; }
Show OutputOutput
codeaft@codeaft:~$ g++ codeaft.cpp
codeaft@codeaft:~$ ./a.out 1 codeaft@codeaft:~$
Comments and Reactions
What Next?
C++ Control Statements