I know, boolean variables are NO by default.
BOOL first;
BOOL second;
if (first != second) {
NSLog(@"Yes");
}else{
NSLog(@"NO");
}
The OutPut is :Yes
But when i assign NO to first and second, i got ‘NO’ out put.
first = NO;
second = NO;
if (first != second) {
NSLog(@"Yes");
}else{
NSLog(@"NO");
}
The OutPut is: NO
Where is the problem? Or should boolean variables exactly take NO by default? Or Depending on compiler?
I have used Xcode 4.2 version. I don’t understand where the problem is. Please explain any one with example. Thanks in advance.
Local variables are not initialized by default; you get random garbage in them. You should initialize them with
BOOL first = NO;if you want them to have a reasonable value.