हिंदी

What does the following program output to the monitor: int value = 0; int count = 1; value = ++count; /* note change from previous */ System.out.println("value:" + value "+ count:" + count );

Advertisements

प्रश्न

What does the following program output to the monitor:

int value = 0;
int count = 1;
value = ++count; /* note change from previous */
System.out.println("value:" + value "+ count:" + count );
दीर्घउत्तर
Advertisements

उत्तर

Initially, the variable value is assigned 0, and the variable count is assigned 1.

The statement value = count++; uses the post-increment operator (++). This operator first assigns the original value of count to value and then increases the value of count by 1.

Therefore, after executing the statement:

  • value = 1
  • count = 2

However, the given program contains a syntax error in the System.out.println() statement because the concatenation operator (+) is missing between value and "+ count:".

System.out.println("value:" + value + " count:" + count);

Output:

value:1 count:2

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 6: Variables and Expressions - EXERCISE [पृष्ठ १३२]

APPEARS IN

धीरज मेहरोत्रा Computer Science [English] Class 12
अध्याय 6 Variables and Expressions
EXERCISE | Q 41. | पृष्ठ १३२
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×