sir if i declare a variable but i don’t assign any value to it so it will have garbage value or 0 value
sir i printed a variable after declaring it
it prints 0 only
whereas shouldn’t it be garbage value?
sir if i declare a variable but i don’t assign any value to it so it will have garbage value or 0 value
sir i printed a variable after declaring it
it prints 0 only
whereas shouldn’t it be garbage value?
hey Yatin, it depends upon compiler to compiler. In latest compiler it mostly gives 0 for single variable but if you declare an array that it contains garbage values.
ok sir and what happens for the pointer
if i do the same
i declare it and print it without storing any address
int *p;
cout<<p;
it gave zero in all data types but nothing in char *
hey @yatin, consder the below explanation,
char ch;
cout<<ch; //no output
when you print char pointer using cout, it always gives to content of char variable it pointing to instead of address due to operator overloading.
char ch=‘A’;
char* ptr=&ch;
cout<<ptr; //output=A
So an empty character pointer will give no answer as there is no content available for it to point.
sir in int and float pointer case also there is nothing to point ,but they do print 0 value
Hey @yatin, yes int and float will gave you 0 as there is nothing available for them to point
Remember, It is good programming habit to initialise the pointer with NULL at the time of declaration.