What will be the output of the following C++ code? [code] #include <cstdlib> #include <iostream> using namespace std;

Quốc Ân

New member
What will be the output of the following C++ code?
Code:
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    int main()
    {
        int ran = rand();
        cout << ran << endl;
    }
A. Any number
B. 89
C. 0 to RAND_MAX
D. 79
 
Answer: c
Explanation: 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.
Output:
Code:
$ g++ rand.cpp
$ a.out
574
 

Tìm kiếm

Back
Top