What is the error in the below program? class Program { Static Void Main(String[] args) { const int x= 100; int y= 10; const int z= y/ 5 * 100 * y; Console.WriteLine(x * z); Console.ReadLine(); } }

Back to Questions
A)

'z 'should not be declared as constant

B)

Expression (x * z) is invalid

C)

The expression being assigned to 'z' must be constant

D)

'x' is declared in invalid format

 

Author Explanation :

'z' should be declared as const int z = 10/5 * 100*10 i.e only constant values should be assigned to a constant.

Answers Posted

PostedBy By: srinivas, at 11:10 AM on 15-October-2019

Answer Posted: A

Explanation: 'z 'should not be declared as constant

Result: Wrong Answer

PostedBy By: prakash.shrestha@inspopindia.com, at 04:09 AM on 16-July-2019

Answer Posted: C

Explanation: Variable y should be constant.

Result: Correct

PostedBy By: Jigar Shah, at 12:09 PM on 05-April-2019

Answer Posted: C

Explanation: As z is constant, expression assigned to him must be constant

Result: Correct

PostedBy By: jayaprathap, at 05:48 AM on 05-April-2019

Answer Posted:

Explanation: its an invalid

Result: Wrong Answer

PostedBy By: krishna, at 05:36 AM on 05-April-2019

Answer Posted: C

Explanation: if yp declare constant you should put a constant value not the expressipn. ifexpression is needed then no point un keeping const keyword

Result: Correct

PostedBy By: Hussam Uddin, at 04:50 AM on 05-April-2019

Answer Posted:

Explanation: We cannot declare console.writeline(x*z);,B is the ans

Result: Wrong Answer

PostedBy By: Sagar , at 04:27 AM on 05-April-2019

Answer Posted: C

Explanation: It will work if 'y' is constant

Result: Correct

PostedBy By: Sumathi Yerramsetti, at 04:08 AM on 05-April-2019

Answer Posted: C

Explanation: z should not be a const

Result: Correct

PostedBy By: Sumathi Yerramsetti, at 04:07 AM on 05-April-2019

Answer Posted:

Explanation: z should not be a const

Result: Wrong Answer

Back to Questions

© Copyright 1997 - 2019 | www.bestdotnettraining.com | www.deccansoft.com | All Rights Reserved.
 
Bestdotnet google plus
Enquiry Now