- Basic Objective-C
- Objective-C - Home
- Objective-C - Overview
- Objective-C - Environment Setup
- Objective-C - Program Structure
- Objective-C - Basic Syntax
- Objective-C - Data Types
- Objective-C - Variables
- Objective-C - Constants
- Objective-C - Operators
- Objective-C - Loops
- Objective-C - Decision Making
- Objective-C - Functions
- Objective-C - Blocks
- Objective-C - Numbers
- Objective-C - Arrays
- Objective-C - Pointers
- Objective-C - Strings
- Objective-C - Structures
- Objective-C - Preprocessors
- Objective-C - Typedef
- Objective-C - Type Casting
- Objective-C - Log Handling
- Objective-C - Error Handling
- Command-Line Arguments
- Advanced Objective-C
- Objective-C - Classes & Objects
- Objective-C - Inheritance
- Objective-C - Polymorphism
- Objective-C - Data Encapsulation
- Objective-C - Categories
- Objective-C - Posing
- Objective-C - Extensions
- Objective-C - Protocols
- Objective-C - Dynamic Binding
- Objective-C - Composite Objects
- Obj-C - Foundation Framework
- Objective-C - Fast Enumeration
- Obj-C - Memory Management
- Objective-C Useful Resources
- Objective-C - Quick Guide
- Objective-C - Useful Resources
- Objective-C - Discussion
Logical Operators in Objective-C
Following table shows all the logical operators supported by Objective-C language. Assume variable A holds 1 and variable B holds 0, then −
Operator | Description | Example |
---|---|---|
&& | Called Logical AND operator. If both the operands are non zero then condition becomes true. | (A && B) is false. |
|| | Called Logical OR Operator. If any of the two operands is non zero then condition becomes true. | (A || B) is true. |
! | Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true, then Logical NOT operator will make false. | !(A && B) is true. |
Example
Try the following example to understand all the logical operators available in Objective-C programming language −
#import <Foundation/Foundation.h> int main() { int a = 5; int b = 20; if ( a && b ) { NSLog(@"Line 1 - Condition is true\n" ); } if ( a || b ) { NSLog(@"Line 2 - Condition is true\n" ); } /* lets change the value of a and b */ a = 0; b = 10; if ( a && b ) { NSLog(@"Line 3 - Condition is true\n" ); } else { NSLog(@"Line 3 - Condition is not true\n" ); } if ( !(a && b) ) { NSLog(@"Line 4 - Condition is true\n" ); } }
When you compile and execute the above program, it produces the following result −
2013-09-07 22:35:57.256 demo[19012] Line 1 - Condition is true 2013-09-07 22:35:57.256 demo[19012] Line 2 - Condition is true 2013-09-07 22:35:57.256 demo[19012] Line 3 - Condition is not true 2013-09-07 22:35:57.256 demo[19012] Line 4 - Condition is true
objective_c_operators.htm
Advertisements
To Continue Learning Please Login
Login with Google