• Home
  • DSA
  • Concept
  • Interview
  • Tips&Tricks
  • Tutorial Videos
  • Home
  • DSA
  • Concept
  • Interview
  • Tips&Tricks
  • Tutorial Videos
  • #News
  • #APPS
  • #Events
    • #WWDC
    • #I/O
    • #Ignite
  • #Let’s Talk
  • #Advertise

MyCodeTips mycodetips-newlogocopy1

  • Home
  • DSA
  • Concept
  • Interview
  • Tips&Tricks
  • Tutorial Videos
Objective-c

Objective-C Operators

Objective-C Operators , Objective-C also provides a set of so called logical operators designed to return boolean true and false. The OR (||) operator returns 1 if one of its two operands evaluates to true, otherwise it returns 0

sizeof Operator

sizeof() returns the size of an variable. sizeof(anInteger) will return 4.

Conditional Expression

value = condition ? X:Y is called the Conditional Expression.

If Condition is true ? Then assign X to value, Otherwise assign Y to value.

Conditional operator ? : can be used to replace if...else statements. It has the following general form:

Exp1 ? Exp2 : Exp3;
Where Exp1, Exp2, and Exp3 are expressions. Notice the use and placement of the colon.

The value of a ? expression is determined like this: Exp1 is evaluated. If it is true, then Exp2 is evaluated and becomes the value of the entire ? expression. If Exp1 is false, then Exp3 is evaluated and its value becomes the value of the expression.

Address Operator

& returns the address of an variable. &a; will give actual address of the variable.

Pointer * operator

* is the Pointer operator to a variable. *a; will pointer to a variable.

Arithmetic Operators

OperatorDescription
+Adds two operands
–Subtracts second operand from the first
*Multiplies both operands
/Divides numerator by denominator
%Modulus Operator and remainder of after an integer division
++Increment operator increases integer value by one
—Decrement operator decreases integer value by one

Relational Operators

OperatorDescription
==Checks if the values of two operands are equal or not.
!=Checks if the values of two operands are not equal.
>Checks if the value of left operand is greater than the value of right operand.
<Checks if the value of left operand is less than the value of right operand.
>=Checks if the value of left operand is greater than or equal to the value of right operand.
<=Checks if the value of left operand is less than or equal to the value of right operand.

Logical Operators

OperatorDescription
&&Logical AND operator. If both the operands are non zero then condition becomes true.
||Logical OR Operator. If any of the two operands is non zero then condition becomes true.
!Logical NOT Operator. Reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make false.

Bitwise Operators

OperatorDescription
&Binary AND Operator copies a bit to the result if it exists in both operands.
|Binary OR Operator copies a bit if it exists in either operand.
^Binary XOR Operator copies the bit if it is set in one operand but not both.
~Binary Ones Complement Operator is unary and has the effect of ‘flipping’ bits.
<<Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand.
>>Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.
pqp & qp | qp ^ q
00000
01011
11110
10011

Assignment Operators

=Assignment operator, Assigns values from right side operands to left side operand
+=Add AND assignment operator, It adds right operand to the left operand and assigns the result to left operand
-=Subtract AND assignment operator, It subtracts right operand from the left operand and assigns the result to left operand
*=Multiply AND assignment operator, It multiplies right operand with the left operand and assigns the result to left operand
/=Divide AND assignment operator, It divides left operand with the right operand and assigns the result to left operand
%=Modulus AND assignment operator, It takes modulus using two operands and assigns the result to left operand
<<=Left shift AND assignment operator
>>=Right shift AND assignment operator
&=Bitwise AND assignment operator
^=bitwise exclusive OR and assignment operator
|=bitwise inclusive OR and assignment operator

Compound Assignment Operators

OperatorDescription
x += yAdd x to y and place result in x
x -= ySubtract y from x and place result in x
x *= yMultiply x by y and place result in x
x /= yDivide x by y and place result in x
x %= yPerform Modulo on x and y and place result in x
x &= yAssign to x the result of logical AND operation on x and y
x |= yAssign to x the result of logical OR operation on x and y
x ^= yAssign to x the result of logical Exclusive OR on x and y

Increment and Decrement Operators

x = x + 1; // Increase value of variable x by 1

x = x - 1; // Decrease value of variable x by 1	

x++; Increment x by 1

x--; Decrement x by 1

Comparison Operators

if (x == y)
      // Perform task

Boolean Logical Operators

bool flag = true; //variable is true
bool secondFlag;

secondFlag = !flag; // secondFlag set to false


if ((10 < 20) || (20 < 10))
        NSLog (@"Expression is true");


if ((10 < 20) && (20 < 10))
      NSLog (@"Expression is true");

The Ternary Operator

[condition] ? [true expression] : [false expression]

int x = 10;
int y = 20;

NSLog(@"Largest number is %i", x > y ? x : y );

Happy Coding 🙂

Liked it? Take a second to support Ranjan on Patreon!
become a patron button
  • Click to share on Reddit (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • More
  • Click to share on Pocket (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
Written by Ranjan - 4289 Views
Tags | APP Programming, Apps, IOS
AUTHOR
Ranjan

Namaste, My name is Ranjan, I am a graduate from NIT Rourkela. This website is basically about of what i learnt from my years of experience as a software engineer on software development specifically on mobile application development, design patterns/architectures, its changing scenarios, security, troubleshooting, tools, tips&tricks and many more.

You Might Also Like

objective-c-datatypes1

Objective-C Data Types

November 12, 2021
optional-swift

Optional in Swift !

October 2, 2021
Passing data between view controllers in Objective-C

Passing data between view controllers in Objective-C

November 23, 2021
Next Post
Previous Post

Support us

mycodetips mycodetips
Follow us @ LinkedIn 2850+

Subscribe for updates

Join 8,213 other subscribers

Latest Posts

  • YT-Featured-solidprinciples
    SOLID Principles of Software Design
  • IOS 16 Features
    Latest features in IOS 16
  • r-language
    How can R language be used for data analysis?
  • wordpress-coding-blog
    Guide To WordPress Coding Standards
  • YT-Featured-Algorithm
    What is Algorithm?
  • Frameworks of IOS
    Frameworks of IOS – Part ( I )
  • NSFileManager or NSPathUtilities
    NSFileManager or NSPathUtilities in Objective-C
  • Passing data between view controllers in Objective-C
    Passing data between view controllers in Objective-C
  • structures-classes-enum
    Structures and Classes in swift !
  • control-system-swift
    Control Flow in Swift
whiteboard

Whiteboard(PRO)

whiteboard

Whiteboard(lite)

alphabets

Kids Alphabet

techlynk

Techlynk

techbyte

Do2Day

techbyte

Techbyte

  • #about
  • #myapps
  • #contact
  • #privacy
  • #Advertise
  • #Guestpost
  • #myQuestions

Android Android Studio API APP Programming Apps blogging CSS DATABASE dsa Features HTML HTML5 installation Interview Questions IOS iPhone javascript Mac objective-c OS Programming quicktips SDK SEO SQL swift Tips & Tricks Tools UI Web Wordpress Xcode

  • SOLID Principles of Software Design
  • Latest features in IOS 16
  • How can R language be used for data analysis?
  • Guide To WordPress Coding Standards
  • What is Algorithm?

©mycodetips.com