Open In App

Output of C++ programs | Set 50

Predict the output of the following C++ programs:
 




#include <iostream>
using namespace std;
int main()
{
    void a = 10, b = 10;
    int c;
    c = a + b;
    cout << c;
    return 0;
}

1804289383




#include <iostream>
 
using namespace std;
 
int array1[] = { 1200, 200, 2300, 1230, 1543 };
int array2[] = { 12, 14, 16, 18, 20 };
int temp, result = 0;
int main()
{
    for (temp = 0; temp < 5; temp++) {
        result += array1[temp];
    }
    for (temp = 0; temp < 5; temp++) {
        result += array2[temp];
    }
    cout << result;
    return 0;
}

2147483647




#include <iostream>
using namespace std;
int main()
{
    int a = 5, b = 10, c = 15;
    int arr[3] = { &a, &b, &c };
    cout << *arr[*arr[1] - 8];
    return 0;
}

Compile time error




#include <iostream>
using namespace std;
int main()
{
    int array[] = { 10, 20, 30 };
    cout << -2 [array];
    return 0;
}

6553




#include <iostream>
using namespace std;
int main()
{
    int const p = 5;
    cout << ++p;
    return 0;
}

Compile time error!
cannot convert from ‘int *’ to ‘int’




#include <iostream>
using namespace std;
int main()
{
    char arr[20];
    int i;
    for (i = 0; i < 10; i++)
        *(arr + i) = 65 + i;
    *(arr + i) = '\0';
    cout << arr;
    return (0);
}

-30




#include <iostream>
using namespace std;
int Add(int X, int Y, int Z)
{
    return X + Y;
}
double Add(double X, double Y, double Z)
{
    return X + Y;
}
int main()
{
    cout << Add(5, 6);
    cout << Add(5.5, 6.6);
    return 0;
}

Compile time Error!




#include <iostream>
using namespace std;
#define PR(id) cout << "The value of " #id " is " << id
int main()
{
    int i = 10;
    PR(i);
    return 0;
}

ABCDEFGHIJ





Compile time error!




#include <iostream>
using namespace std;
#define PR(id) cout << "The value of " #id " is " << id
int main()
{
    int i = 10;
    PR(i);
    return 0;
}

The value of i is 10

sing.inbox@gmail.com.

 


Article Tags :