int a=3; int b=2; int c=a,b; What will be the value of c?? | Sololearn: Learn to code for FREE!


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.

12/3/2021 12:05:34 PM

Ashutosh Modgil

4 Answers

New Answer


Comma as separator and operator can indeed make confusion : )


No, it will give an error. Please continue the C course on sololearn and also test the code snippets on your own.


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 : ?


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.