Examveda

What will be the output of the following C++ code?
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main()
{
    srand((unsigned)time(0));
    int ran;
    int low = 1, high = 10;
    int range = (high - low) + 1;
    for(int index = 0; index < 1; index++)
    {
        ran = low + int(range * rand() / (RAND_MAX + 1.0));
        cout << ran << endl;
    }
}

A. 1

B. 2

C. 3

D. 4

Answer: Option A


Join The Discussion

Related Questions on C plus plus miscellaneous

What is the difference between '++i' and 'i++' in C++?

A. None of the above

B. They both have the same effect

C. '++i' increments the value of 'i' before returning it, while 'i++' increments the value of 'i' after returning it

D. '++i' increments the value of 'i' after returning it, while 'i++' increments the value of 'i' before returning it