Before I initialise a variable has it taken a value?
For example I have got a code like that:
The output is that: a=2147348480Code:include <stdio.h> main() { const int a; printf("a=%d\n",a); return 0; }
What is that number? Is it random?
Before I initialise a variable has it taken a value?
For example I have got a code like that:
The output is that: a=2147348480Code:include <stdio.h> main() { const int a; printf("a=%d\n",a); return 0; }
What is that number? Is it random?
It is the contents of the memory location where a was stored. No new value was put there by you, consequently whatever was already there is still there.
No, it's garbage.
And since integers are allowed to have trap representations, it might just crash your program.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
yeah const wouldn't allow you to modify a variable. sort of like #define.
It is always good to initialize your variables to 0 on declaration..what I learnt anyways.
and a could have anything stored in it..not just 2147344384
You ended that sentence with a preposition...Bastard!