---
title: "Objective-C Program Structure"  
description: "structure is another user-defined data type available in Objective-C programming which allows you to combine data items of different kinds."  
author: "Tarun Kumar"  
published: 2015-07-06  
updated: 2026-05-13  
canonical: https://www.mindstick.com/articles/1808/objective-c-program-structure  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Objective-C Program Structure

Previously we seen methods to create objects in Objective C : [Objective C : object creation method explanations](http://www.mindstick.com/Blog/10915/Objective%20C%20object%20creation%20method%20explanations#.VZzJ11i6bIU) \

\

Objective-C arrays allow you to define type of [variables](https://www.mindstick.com/articles/715/php-variables) that can hold several data items of the same kind but [structure](https://www.mindstick.com/forum/1188/how-to-create-structure-in-c) is another user-defined data type available in Objective-C [programming](https://yourviews.mindstick.com/view/88478/vibe-coding-the-rise-of-ai-assisted-programming) which allows you to combine data items of different kinds.

\

##### Objective-C program basically consists ofthe following parts:

§ Preprocessor Commands

§ [Interface](https://www.mindstick.com/articles/12036/interface-in-c-sharp)

§ [Implementation](https://answers.mindstick.com/qa/44913/who-is-the-minister-of-statistics-and-programme-implementation)

§ Method

§ Variables

§ Statements & Expressions

§ Comments

##### Let uslook at a simple code that would print the words "Hello World":

**\**

```
#import <Foundation/Foundation.h>@interface SampleClass:NSObject    - (void)sampleMethod;@end@implementation SampleClass   - (void)sampleMethod {            NSLog(@"Hello, World! \n");}@endint main(){   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];      /* my first program in Objective-C */   SampleClass *sampleClass = [[SampleClass alloc]init];   [sampleClass sampleMethod];       [pool drain];   return 0;}
```

##### Compile & Execute Objective-C Program:

\

Now when we compile and run the program, we will get the following result.

\

*```
2015-07-09 08:28:58.203 demo[11674] Hello, World!
```*

##### Let uslook various parts of the above program:

##### \

**1.** The first line of the program #import<[Foundation](https://www.mindstick.com/blog/159/mfc-microsoft-foundation-class)/Foundation.h> is a preprocessor command, which tellsa Objective-C compiler to include Foundation.h file before going toactual compilation.

**2.** The next line @interface SampleClass:NSObjectshows how to create an interface. It inherits NSObject, which is thebase class of all objects.

**3.** The next line - (void)sampleMethod;shows how to declare a method.

**4.** The next line @end marks the end of aninterface.

**5.** The next line @implementation SampleClassshows how to implement the interface SampleClass.

**6.** The next line - (void)sampleMethod{}shows the implementation of the sampleMethod.

**7.** The next line @end marks the end of animplementation.

**8.** The next line int main() is the mainfunction where program [execution](https://www.mindstick.com/blog/178/synchronous-and-asynchronous-command-execution-in-c-sharp-dot-net) begins.

**9.** The next line /*...*/ will be ignoredby the compiler and it has been put to [add additional](https://answers.mindstick.com/qa/51610/can-i-add-additional-or-custom-ringtones-to-the-iphone) comments in the program.So such lines are called comments inthe program.

**10.** The next line NSLog(...) is anotherfunction available in Objective-C which causes the message "Hello, World!"to be displayed on the screen.

**11**. The next line return 0; terminates main()functionand returns the value 0.

Next, wewill learn about : Objective C - [Pointers](https://www.mindstick.com/articles/269710/deep-c-sharp-what-s-the-matter-with-pointers)

---

Original Source: https://www.mindstick.com/articles/1808/objective-c-program-structure

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
