---
title: "Use of undeclared identifier “sum”"  
description: "Use of undeclared identifier “sum”"  
author: "Anonymous User"  
published: 2015-08-04  
updated: 2015-08-05  
canonical: https://www.mindstick.com/forum/33395/use-of-undeclared-identifier-sum  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# Use of undeclared identifier “sum”

I have repeated [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) 3rd time, but I could not found that what is [mean](https://yourviews.mindstick.com/view/80768/what-does-real-minority-mean) of use of undeclared identifier ..

I wrote that [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) on [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) in objective-C

```
#import <Foundation/Foundation.h>
 @interface Add:NSObject
 /* method declaration */
 - (int)add:(int)a andNum2:(int)b;
@end

@implementation Add
 /* method returning the max between two numbers */
 - (int)add:(int)a andNum2:(int)b {
/* local variable declaration */
int sum = a +b;return sum;
}
@end
  NSLog(@"sum is : %d", sum);// error this line    
  return 0;}
```

## Replies

### Reply by Tarun Kumar

You can do like here:

```
#import <Foundation/Foundation.h>
 @interface  Add:NSObject {
    int sum;//Declare sum as global variable to access in class
 }
 - (int)add:(int)a andNum2:(int)b;
 @end
  @implementation Add
   - (int)add:(int)a andNum2:(int)b {
   sum = a +b;
   return sum;
}
 @end
```

NSLog(@"sum is : %d", sum);//Now Access global variable with in class.


---

Original Source: https://www.mindstick.com/forum/33395/use-of-undeclared-identifier-sum

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
