Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About pointers in Objective-C

I stumbled across the following and can't seem to work out why this works. Please can you explain why I don't need to use a pointer before range?

NSString *d = @"The quick brown fox";
NSRange range = [d rangeOfString:@"brown"];
like image 943
vboombatz Avatar asked Nov 30 '11 23:11

vboombatz


People also ask

What is pointers in C with example?

A pointer is a variable that stores the address of another variable. Unlike other variables that hold values of a certain type, pointer holds the address of a variable. For example, an integer variable holds (or you can say stores) an integer value, however an integer pointer holds the address of a integer variable.

What is pointers and its types?

There are majorly four types of pointers, they are: Null Pointer. Void Pointer. Wild Pointer. Dangling Pointer.

What is pointer in C and its advantages?

The Pointer in C, is a variable that stores address of another variable. A pointer can also be used to refer to another pointer function. A pointer can be incremented/decremented, i.e., to point to the next/ previous memory location. The purpose of pointer is to save memory space and achieve faster execution time.

What do you mean by pointers?

Definition of pointer 1a Pointers plural : the two stars in the Big Dipper a line through which points to the North Star. b : one that points out especially : a rod used to direct attention. c : a computer memory address that contains another address (as of desired data)


1 Answers

NSString is an object type. All object types are pointers and can't be created on the stack. NSRange is a C-struct. Structs can be created on the stack, and thus aren't necessarily all pointers.

There isn't a good guide to know which ones are objects, and which are structs. You'll just have to check for each type as you move forward.

like image 113
Joshua Weinberg Avatar answered Oct 03 '22 23:10

Joshua Weinberg