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.
4 Respostas
+ 3
Comma as separator and operator can indeed make confusion : )
https://sillycodes.com/comma-operator-in-c-programming/
+ 1
No, it will give an error.
Please continue the C course on sololearn and also test the code snippets on your own.
+ 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 : ?
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.