---
title: "What is id in Objective C?"  
description: "What is id in Objective C?"  
author: "Tarun Kumar"  
published: 2015-07-15  
updated: 2020-09-12  
canonical: https://www.mindstick.com/interview/2703/what-is-id-in-objective-c  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# What is id in Objective C?

id can hold pointer of any kind of object. \
**syntax:**

id newPointer = somepointer; \
**e.g.** *\*

```
NSString *str = @"karm";id newStr = str;
```

\
It will work perfectly. Here is something you should note that id keyword is not followed by an *, its because id already knows that it is a pointer.\
\
We use this while return objects from the derived class while we overrige the init method as shown below:

```
-(id)init 
  {
    if (self = [super init])
    {
       someIVarObject = [SomeClass alloc] init];
    }
    return self;
  }
```

Here we return id because somebody can initialize an object like this.\
BaseClass *base = [[DerivedClass alloc] init];\
In this case, we want to make sure we have the right pointer returned from the init method.\
\
**Summary:**

1. id is a reserved keyword.
2. It can hold pointer to any object.
3. It can hold pointer to nil.

## Answers

### Answer by Tarun Kumar

id can hold pointer of any kind of object. \
**syntax:**

id newPointer = somepointer; \
**e.g.** *\*

```
NSString *str = @"karm";id newStr = str;
```

\
It will work perfectly. Here is something you should note that id keyword is not followed by an *, its because id already knows that it is a pointer.\
\
We use this while return objects from the derived class while we overrige the init method as shown below:

```
-(id)init 
  {
    if (self = [super init])
    {
       someIVarObject = [SomeClass alloc] init];
    }
    return self;
  }
```

Here we return id because somebody can initialize an object like this.\
BaseClass *base = [[DerivedClass alloc] init];\
In this case, we want to make sure we have the right pointer returned from the init method.\
\
**Summary:**

1. id is a reserved keyword.
2. It can hold pointer to any object.
3. It can hold pointer to nil.


---

Original Source: https://www.mindstick.com/interview/2703/what-is-id-in-objective-c

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
