Know about Datatypes in Objective C

In this post i will tell you about data types that are used in Objective-c . As before starting to build apps , we need to know about the basics of this programming language.

What are Data types ?

Data type of a value is defined as a attribute which tells what kind of value can store in it . Objective-c datatypes are same as that of c or c++.

Types of Data types :

1)
Integer types : The int data type (integer) is used to store integral values or whole numbers (i.e numbers don`t contain a decimal point).The int stores 32-bits of memory.


eg :- int valName = 1;

Here int is the datatype
         valName is the name of the variable
         
Type prefixes :
  • signed – indicates that both positive and negative numbers will be stored. Eg- signed int
  • unsigned  – indicates that only positive numbers will be store. Eg- unsigned int
  • short  –   reduces the amount of storage used by the int type from 32-bits to 16-bits. Eg- short int
  • long  – increases the amount of storage used by the int type from 32-bits to 64-bits. Eg- long int
2) Floating point types :  Floating point types are used to store decimal point values in the variable.
Floating point types are of two types :

  • Float -Float is a 32-bit floating datatype which is used to store Decimal values. Eg- float val = 0.13.
  • Double- -Double is a 64-bit floating datatype which is used to store Decimal values. Eg- float val = 0.1343456575343.
3) Strings : Strings are the datatypes which are used to store the collection of characters in it .Eg - Hello is a string .
Declaration of the string in Objective-c:

NSString *strName = @"Hello";

Here , NSString is used to initialize the string class    (NS is NEXT STEP)
           * is a pointer which is used initialize the object name 
           strName is the name of the object of string class.
           @"" is used to set value to object strName.

There are types of NSString`s, also which i`ll tell you in my future posts.

I will tell you about the collection datatypes (i.e Arrays, Dictionaries, Sets) in my future posts. Now in my next post we will move straight to the app development . 

Thank You :)

Comments

Popular Posts