Question

Consider the code snippet given below. The variable sum is of type int. Will this compile?...

Consider the code snippet given below. The variable sum is of type int. Will this compile? Explain why or why not

int sum = 2 + ’2’;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

yes the code snippest compile.

int sum = 2 + '2';

Here '2' is a character, int is a integer type data type.

Compiler take the ASCII value of '2'.

The ASCII value of the '2' is 50.

int sum = 2 + 50;

int sum = 52;

So the out of the sum is 52.

Any doubts leave a comment

Add a comment
Know the answer?
Add Answer to:
Consider the code snippet given below. The variable sum is of type int. Will this compile?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT