Find the output of following C++ programs
Program 1
kw.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;
}
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out Unequal kodingwindow@kw:~$
Program 2
kw.cpp
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    cout<<setprecision(52);
    double d = 3.14;
    cout<<d<<endl;
    return 0;
}
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out 3.140000000000000124344978758017532527446746826171875 kodingwindow@kw:~$
Program 3
kw.cpp
#include <iostream>
using namespace std;
int main()
{
    int x, y = 0;
    if ((x = y = 1) == 1)
        cout<<x<<" "<<y<<endl;
    return 0;
}
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out 1 1 kodingwindow@kw:~$
Program 4
kw.cpp
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    cout<<strlen("Hello World\0\n")<<"\n";
}
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out 11 kodingwindow@kw:~$
Program 5
kw.cpp
#include <iostream>
using namespace std;
int main()
{
    bool a = 0101;
    cout<<a<<endl;
}
kodingwindow@kw:~$ g++ kw.cpp
kodingwindow@kw:~$ ./a.out 1 kodingwindow@kw:~$
Advertisement