X=5; Y=++X; Print X; Print Y; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

X=5; Y=++X; Print X; Print Y;

Expecting output. What is the value of X and Y

29th Mar 2023, 10:14 AM
Sanjay S
19 Answers
0
6 6
30th Mar 2023, 5:49 PM
Sourabh Yadav
Sourabh Yadav - avatar
+ 6
Sanjay S , reading your last post, i am not really sure what your issue or question is. can you please give us some more details?
29th Mar 2023, 10:56 AM
Lothar
Lothar - avatar
+ 5
Sanjay S , is this a *quiz* or what other purpose does your post have?
29th Mar 2023, 11:21 AM
Lothar
Lothar - avatar
+ 5
Sanjay S , > the q&a section is for *coding related questions* only. this does *not include quizzes*. > for promoting codes, quizzes and and other stuff like this, please use the *community* section feed.
29th Mar 2023, 5:08 PM
Lothar
Lothar - avatar
+ 3
Hard to say, for example, ++Y can have different meaning by language, not all languages has it or use it. Output printing also differs, some may support comma separator, other needs formatting or string concatenation. Maybe you could describe the problem in non-programming-language style? what's your doubt actually?
29th Mar 2023, 10:43 AM
Ipang
+ 2
In C, C++, Java, C# and several similarly syntactic languages, the pre-increment operator ++(variable) immediately affects its <variable> operand. Meaning <x> will be incremented by one before its already-incremented-value (6) is assigned to <y> Had you assigned to <y> using post-increment operator (variable)++ like this ... int y = x++; <y> will get original <x> value (5). Value incrementation is not happening yet, value incrementation will take place after the line and the (optional) semicolon (command separator) had been successfully processed / executed.
29th Mar 2023, 11:05 AM
Ipang
+ 2
It is 6 and 6
29th Mar 2023, 11:44 AM
Волгина Варвара
Волгина Варвара - avatar
+ 1
Are you sure it's C# code (tagged language - edited)? there's no type definition for the variables. Also C# uses Console.Write() or Console.WriteLine(), not just "Print"
29th Mar 2023, 10:28 AM
Ipang
+ 1
Ipang I edited my question please consider the question now.
29th Mar 2023, 10:53 AM
Sanjay S
+ 1
Lothar Thank you for showing interest. I am declaring a two variables x and y. And am intializing a x with value 5 and am assigning a preincrement value of x to y. So now am printing a x and y now to console. What is the value of x and y will get
29th Mar 2023, 11:00 AM
Sanjay S
+ 1
Ipang Thank you
29th Mar 2023, 11:20 AM
Sanjay S
+ 1
X= 5 ,y=6 .....Maybe
29th Mar 2023, 6:11 PM
Piyush Maru
Piyush Maru - avatar
+ 1
Sanjay S Just run the code in Code Playground and you'll see the output of any code you want
30th Mar 2023, 1:14 AM
Emerson Prado
Emerson Prado - avatar
+ 1
The final output will be 6&6
30th Mar 2023, 6:57 AM
Subhasmita Dash
Subhasmita Dash - avatar
+ 1
6 & 6
30th Mar 2023, 2:26 PM
guneswari
0
Sorry it is not C# code. Irrespective of specific coding language syntax I want answer
29th Mar 2023, 10:31 AM
Sanjay S
0
Like quiz only
29th Mar 2023, 11:23 AM
Sanjay S
0
w = input ("выберите действие; '+' '-' '/' '*': ") y = input ("введите первое число: ") x = input ("введите первое число") if w = "+": a = y + x print ("результат: " + str(a)) elif w = w = "-": a = y - x print ("результат: " + str(a)) elif w = w = "/": a = y / x print ("результат: " + str(a)) elif w = w = "*": a = y * x print ("результат: " + str(a)) else: print ("некорректно введены данные") input ()
30th Mar 2023, 5:58 PM
паша далдалвышал
паша далдалвышал - avatar
0
I am read a html
31st Mar 2023, 5:15 AM
Ranjith Bhargav
Ranjith Bhargav - avatar