Why is the following statement legal in C but not in Java? [duplicate]












0
















This question already has an answer here:




  • Ternary operator in java vs c [duplicate]

    1 answer




Why is the following statement legal in C but not in Java?



int k = 1;
(10 < 20) ? k++ : k--;









share|improve this question















marked as duplicate by Sotirios Delimanolis java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 17:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 15





    Because Java is not C

    – Hovercraft Full Of Eels
    Nov 15 '18 at 3:54






  • 2





    Neither of the proposed dupes addresses the OP's question. The problem they address deals with using non-expression statements on the RHS. The OP's problem is caused by the absence of the LHS.

    – DYZ
    Nov 15 '18 at 4:02













  • @flakes: Make that an answer after this is reopened.

    – R..
    Nov 15 '18 at 4:27
















0
















This question already has an answer here:




  • Ternary operator in java vs c [duplicate]

    1 answer




Why is the following statement legal in C but not in Java?



int k = 1;
(10 < 20) ? k++ : k--;









share|improve this question















marked as duplicate by Sotirios Delimanolis java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 17:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 15





    Because Java is not C

    – Hovercraft Full Of Eels
    Nov 15 '18 at 3:54






  • 2





    Neither of the proposed dupes addresses the OP's question. The problem they address deals with using non-expression statements on the RHS. The OP's problem is caused by the absence of the LHS.

    – DYZ
    Nov 15 '18 at 4:02













  • @flakes: Make that an answer after this is reopened.

    – R..
    Nov 15 '18 at 4:27














0












0








0









This question already has an answer here:




  • Ternary operator in java vs c [duplicate]

    1 answer




Why is the following statement legal in C but not in Java?



int k = 1;
(10 < 20) ? k++ : k--;









share|improve this question

















This question already has an answer here:




  • Ternary operator in java vs c [duplicate]

    1 answer




Why is the following statement legal in C but not in Java?



int k = 1;
(10 < 20) ? k++ : k--;




This question already has an answer here:




  • Ternary operator in java vs c [duplicate]

    1 answer








java c ternary-operator






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 3:53









Hovercraft Full Of Eels

262k20212318




262k20212318










asked Nov 15 '18 at 3:52









Zabi KhanZabi Khan

132




132




marked as duplicate by Sotirios Delimanolis java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 17:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Sotirios Delimanolis java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 17:23


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 15





    Because Java is not C

    – Hovercraft Full Of Eels
    Nov 15 '18 at 3:54






  • 2





    Neither of the proposed dupes addresses the OP's question. The problem they address deals with using non-expression statements on the RHS. The OP's problem is caused by the absence of the LHS.

    – DYZ
    Nov 15 '18 at 4:02













  • @flakes: Make that an answer after this is reopened.

    – R..
    Nov 15 '18 at 4:27














  • 15





    Because Java is not C

    – Hovercraft Full Of Eels
    Nov 15 '18 at 3:54






  • 2





    Neither of the proposed dupes addresses the OP's question. The problem they address deals with using non-expression statements on the RHS. The OP's problem is caused by the absence of the LHS.

    – DYZ
    Nov 15 '18 at 4:02













  • @flakes: Make that an answer after this is reopened.

    – R..
    Nov 15 '18 at 4:27








15




15





Because Java is not C

– Hovercraft Full Of Eels
Nov 15 '18 at 3:54





Because Java is not C

– Hovercraft Full Of Eels
Nov 15 '18 at 3:54




2




2





Neither of the proposed dupes addresses the OP's question. The problem they address deals with using non-expression statements on the RHS. The OP's problem is caused by the absence of the LHS.

– DYZ
Nov 15 '18 at 4:02







Neither of the proposed dupes addresses the OP's question. The problem they address deals with using non-expression statements on the RHS. The OP's problem is caused by the absence of the LHS.

– DYZ
Nov 15 '18 at 4:02















@flakes: Make that an answer after this is reopened.

– R..
Nov 15 '18 at 4:27





@flakes: Make that an answer after this is reopened.

– R..
Nov 15 '18 at 4:27












1 Answer
1






active

oldest

votes


















5














This is because in C all expressions can be made into expression-statements by adding a semicolon ;.



In Java not all expressions can be made into expression statements. They must be assignment expressions, use postfix/prefix operators, be method invocations, or new expressions. See more here



Further, a ternary operator in Java requires that each operand be a non void expression and the value returned must be assigned.






share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    This is because in C all expressions can be made into expression-statements by adding a semicolon ;.



    In Java not all expressions can be made into expression statements. They must be assignment expressions, use postfix/prefix operators, be method invocations, or new expressions. See more here



    Further, a ternary operator in Java requires that each operand be a non void expression and the value returned must be assigned.






    share|improve this answer




























      5














      This is because in C all expressions can be made into expression-statements by adding a semicolon ;.



      In Java not all expressions can be made into expression statements. They must be assignment expressions, use postfix/prefix operators, be method invocations, or new expressions. See more here



      Further, a ternary operator in Java requires that each operand be a non void expression and the value returned must be assigned.






      share|improve this answer


























        5












        5








        5







        This is because in C all expressions can be made into expression-statements by adding a semicolon ;.



        In Java not all expressions can be made into expression statements. They must be assignment expressions, use postfix/prefix operators, be method invocations, or new expressions. See more here



        Further, a ternary operator in Java requires that each operand be a non void expression and the value returned must be assigned.






        share|improve this answer













        This is because in C all expressions can be made into expression-statements by adding a semicolon ;.



        In Java not all expressions can be made into expression statements. They must be assignment expressions, use postfix/prefix operators, be method invocations, or new expressions. See more here



        Further, a ternary operator in Java requires that each operand be a non void expression and the value returned must be assigned.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 4:28









        flakesflakes

        6,79812051




        6,79812051

















            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine