What will be the output of following code.
)include <iostream.h>
int sub (int, int);
void main( )
{
int a=2,b=2;
cout <<a<<b<<sub(a,b);
}
int sub (int a, int b)
{
int c;
c= a-b;
return(c);
}
Answers
Answer:
Output of C++ programs | Set 50
Predict the output of the following C++ programs:
Question 1:
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int ran = rand();
cout << ran << endl;
return 0;
}
Output:
1804289383
Explanation: As the declared number is an integer, It will produce the random number from 0 to RAND_MAX. The value of RAND_MAX is library-dependent but is guaranteed to be at least 32767 on any standard library implementation.
Question 2:
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
cout << RAND_MAX << endl;
return 0;
}
Output:
2147483647
Explanation: The output is Compiler Dependent. RAND_MAX is a function used by the compiler to create a maximum random number.
Question 3:
#include <iostream>
using namespace std;
int main()
{
void a = 10, b = 10;
int c;
c = a + b;
cout << c;
return 0;
}
Explanation:
,