• Home
  • Troubleshoot
  • #Example
    • C
    • C++
    • Python
    • R-Programming
  • DSA
  • Quiz
  • Tutorial Videos
  • Home
  • Troubleshoot
  • #Example
    • C
    • C++
    • Python
    • R-Programming
  • DSA
  • Quiz
  • Tutorial Videos
  • #Deals
  • #News
  • #WiKi
  • #APPS
  • #Events
    • #WWDC
    • #I/O
    • #Ignite
  • #Let’s Talk

MyCodeTips mycodetips-newlogocopy1

  • Home
  • Troubleshoot
  • #Example
    • C
    • C++
    • Python
    • R-Programming
  • DSA
  • Quiz
  • 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 🙂

  • 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)
  • Click to share on Pocket (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
Written by Ranjan - 1329 Views
Tags | APP Programming, Apps, IOS
AUTHOR
Ranjan

I m Ranjan and Sharing my years of experience in Software Development. Love to code in Mobile apps (IOS, Android, Power Apps, Xamarin, Flutter), Machine Learning ( Beginner ), Dot Net, Databases ( SQL Server, MySql, SQLite), WordPress, Cloud Computing ( AWS, Azure, Google, MongoDB) and many more as required on project-specific. Besides this love to travel and cook.

You Might Also Like

swift-functions

Swift Functions!

October 13, 2021
objective-c-datatypes1

Objective-C Data Types

November 12, 2021
mycodetips-newlogo2

How to use datatype in IOS or Objective-c

September 26, 2013
Next Post
Previous Post

Subscribe for updates

Join 5,733 other subscribers

whiteboard

Whiteboard(PRO)

whiteboard

Whiteboard(lite)

alphabets

Kids Alphabet

techlynk

Techlynk

techbyte

Do2Day

techbyte

Techbyte

Latest Posts

  • 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
  • swift-concurrency-await
    Concurrency in Swift
  • time-complexity-dsa
    The Term Time Complexity in DSA
  • objective-c-datatypes1
    Objective-C Data Types
  • Convert-jpeg-word
    Convert JPG to Word – Tips You Should Try!
  • objective-c-control-statements2
    Objective-C control statements and loops !

Quick Links

  • #about
  • #myapps
  • #contact
  • #privacy

Other Websites

  • #myQuestions
  • #myBhojanalaya
  • #gadgetFacts
  • #ifscCodesDB

Tag Cloud

Android Android Studio API APP Programming Apps ARC asp.net blogging Browser Config CSS DATABASE DFD error Features GUI HTML HTML5 IDE IIS installation Interview Questions IOS iPhone javascript Mac objective-c OneDrive OS Programming quicktips SDK SEO Settings SMO SQL swift swiftUI Teams Tips & Tricks Tools UI Web Wordpress Xcode

©mycodetips.com