Simple coding question in Dart. #dart #coding #flutter

preview_player
Показать описание
#dart #flutter #coding #codinglife #programming
Рекомендации по теме
Комментарии
Автор

The value of "c" is 'true' because "a" is not 'null' so it can't return the value of "b" rather it will return the value of "a" which is 'true'

ihumark
Автор

The Dart program you provided has a small issue. The `??` operator in Dart is known as the null-aware operator, and it is used to provide a default value when the left-hand side is `null`. However, in your code, `a` and `b` are both non-null boolean values (`true` and `false`), so using `??` here doesn't make much sense.

Here’s the corrected version of the code:

```dart
void main() {
bool a = true;
bool b = false;
bool c = a || b; // Use the logical OR operator instead of the null-aware operator
print(c); // This will print `true` because `a` is true
}
```

### Explanation:
- `a ?? b` would only make sense if `a` could be `null`. Since `a` is always `true` in this case, the `??` operator is not appropriate.
- Instead, if you want to check if either `a` or `b` is `true`, you should use the logical OR operator (`||`).
- The result of `a || b` will be `true` if either `a` or `b` is `true`. In this case, since `a` is `true`, `c` will be `true`.

If you run the corrected code, the output will be:

```
true
```

paulocitytechverse
Автор

True, bcz 'a' is not null so that returns the 'a' value true

akshayar
Автор

C value is true,
because the expression (a ?? b) returns true,
because in this expression "b" will only return when "a" value is null, which in this case is not true.

Ashishlahre
Автор

True, because a is true and not null, if a = null then c=b

wapies
Автор

True as seeing 'a' not null. Also instead of writing 'a ?? b' write 'a' because use of ?? Is unnecessary.

entertainmentshorts...
Автор

I guess the value of C depends on a if statement (if so i can call it) that takes the value of A only if A is true, otherwise it takes any value of B (whether B is true or false).

So i'd say that C is true.

(might be wrong though, i'm still new to flutter and dart)

HuguesMulumba
Автор

Because = is equality since a is true then it's b which is false and c is assigned false assuming = is equality but im seeing the issue now somits probably false

Kenbomp