int a=3; int b=2; int c=a,b; What will be the value of c?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

int a=3; int b=2; int c=a,b; What will be the value of c??

Is this the write way of declarating and assigning (c) the value to the variable.

3rd Dec 2021, 12:05 PM
Ashutosh Modgil
Ashutosh Modgil - avatar
4 Answers
+ 3
Comma as separator and operator can indeed make confusion : ) https://sillycodes.com/comma-operator-in-c-programming/
3rd Dec 2021, 1:01 PM
Ipang
+ 1
No, it will give an error. Please continue the C course on sololearn and also test the code snippets on your own.
3rd Dec 2021, 12:44 PM
Lisa
Lisa - avatar
+ 1
you will have error redeclaration of int b, cos: int a = 3;. // a : 3 int b = 2;. // b : 2 int c = a, b; // c : 3, b : ?
3rd Dec 2021, 12:47 PM
Alexey Kopyshev
Alexey Kopyshev - avatar
0
In your example there, the compiler would be trying to reassign b and fail. --------------------------------------------------------------------------- Your example; #include <stdio.h> int main(void) { int a = 3; int b = 2; int c = a,b; printf("a = %i\nb = %i\nc = %i\n", a,b,c); } //compile error --------------------------------------------------------------------------- Yes you can assign a variable the value of another variable by using: int a = somevlue; Int b = a; This makes b equal to the same value that a had when it was assigned. It does not make them the same all the time. To do that you need to assign the variable the reference address to the value. Int a = somevalue; Int *b = &a; Now when you change int a or int b they are the same. But if you change Int *b they will not be. *b is like the road map to where a is in this current state.
3rd Dec 2021, 12:44 PM
William Owens
William Owens - avatar