Doubt in while video

In the video it is said variable is assigned garbage value but aren’t they assigned default values?

Hey Sonali, in c++ if you don’t initialize a variable with some value then it will be assigned some garbage value by default until you update it with some other value.

But in my case whenever I declare int it is always assigned 0 by default?

Hey Sonali, that’s just by chance.

#include <iostream>
using namespace std;
int main() {
    int n;
    cout<<n;
    return 0;
}

this code snippet can give any random output because in c++ if you don’t initialize a variable with some value then it will be assigned some garbage value by default.