Numbers
- What is the output of this program?
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
cout << RAND_MAX << endl;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
RAND_MAX is a function used by the compiler to create a maximum random number.
- What is the output of this program?
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
int Ran = rand();
cout << Ran << endl;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
As the declared number is 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.
- How many parameters are available in srand function?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
There is one parameter available in srand function. That is an integer value to be used as seed by the pseudo-random number generator algorithm.
- Which is a constant defined in <cstdlib> header file?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
RAND_MAX is a constant defined in <cstdlib> for deciding the maximum random number that can be produced.
- Which header file is used to create the pseudo random generator?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
cstdlib header file is used to create pseudo random number. C++11 standard added random header file as well to generate random numbers.