Q: 1 Find output of the following program?
void main()
{
int a,b;
for(a=1,b=1;a<5,b<10;b++)
cout<<a;
}
Expression syntax error occurred
Prints values from 1 to 9
Prints 1 nine time
Loop made infinite
[ Option C ]
Here, the important point is the comma operator used in the for-loop condition.
for(a=1,b=1; a<5,b<10; b++)
cout << a;
In a for loop, the condition part can use the comma operator (,). When the comma operator is used, all expressions are evaluated, but the result of the last expression decides the loop condition.
Thank you so much for taking the time to read my Computer Science MCQs section carefully. Your support and interest mean a lot, and I truly appreciate you being part of this journey. Stay connected for more insights and updates! If you'd like to explore more tutorials and insights, check out my YouTube channel.
Don’t forget to subscribe and stay connected for future updates.