English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

1)What is the value of x after evaluating:
x+ =x+++--x+4;
if x=3,before the evaluation?

2)Evaluate the following Java expressions where a,b,c are integers and d,f are floating point numbers.
The value of a=5,b=3 and d=1.5 .
(a)f =a+b/a
(b)c=d*a+b
(c)c+(a++)*d+a
(d)f=(++b)*b-a
(e)c=a-(b++)*(__d)

3)Illustrate '?' operator.

4)What is the difference between post-increment and pre-increment?If a=4 gives values of ++a and a++.

5)What is the meaning of variable++?

6)What does the following program output to the monitor:
int value=0;
int value=1;
value=count++;
System.out.println("value"+value"+count:"+count);

2007-04-20 06:06:08 · 2 answers · asked by Sumit 1 in Computers & Internet Programming & Design

2 answers

These questions have a focus around one central theme... pre and post increment/decrement and I shall explain the difference here.

Pre-increment/decrement is when the variable in question begins with a ++ or -- and it means that the value held by the variable is increased/decreased by one BEFORE the variable is used.

If a = 1 then using ++a will mean...

"Take the value of a, add one, then use it in the expression"

Post increment/decrement is the exact opposite of this idea. It increases/decreases the value of the variable AFTER it is used. It is denoted by the ++ or -- after the variable's name.

If a = 1 then using a++ means....

"Take the value of a, use it first in the expression, then add one to it"

With this definition a few of your questions should be pretty darn easy. Like number 5 is pretty much answered. So is number four.... if a =4 then ++a will print 5 because it increments 4 FIRST then prints the value. a++ will print 4 THEN increment by one.

So if you just apply this rule to each of the questions, you will find it pretty easy really. Just break it down.

Hope this helps you out.

2007-04-20 14:06:56 · answer #1 · answered by Martyr2 7 · 0 0

Does your teacher want to grade you or those who post answers to Yahoo?

2007-04-20 13:11:32 · answer #2 · answered by Jim Maryland 7 · 1 0

fedest.com, questions and answers