Find out the output of the given program or error if any.
int main()
{
register int n;
int i;
printf(Enter the no. of loops to run:);
scanf(%d,&n);
for (i=0;i < n;i++)
{
printf(%d\\n,i);
}
}
-
Prints 1 to n
-
Prints 1 to n-1
-
Prints n
-
Infinite loop
-
Compilation error
E
Correct answer
Explanation
error: address of register variable ‘n’ requested
The program will not print any output because there is an error in the program. We cannot refer to the address of a register variable because it is not stored in the memory but on the registers inside the CPU. Only variable stores in the memory have an address.S o there will be an error in the program. Hence this option is correct.