Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7869461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:19:45+00:00 2026-06-03T01:19:45+00:00

#import <Foundation/Foundation.h> @interface Factorial : NSObject +(int) factorial:(int) n; @end @implementation Factorial +(int) factorial:(int)n

  • 0
#import <Foundation/Foundation.h>

@interface Factorial : NSObject 
+(int) factorial:(int) n;
@end

@implementation Factorial

+(int) factorial:(int)n
{
    if (n==0) {
        return 1;
    }
    else
    {
        return [self factorial:n]*[self factorial:n-1];
    }
}

@end

int main (int argc, const char * argv[])
{
    int i = [Factorial factorial:5];
    NSLog(@"%d", i);
    return 0;
}

what is the problem with this code?? i am new in objective-c (i am from c background)
Or, i am getting wrong concept about objective c??

(Compiler generating ..)
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Mon Aug  8 20:32:45 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys002
sharedlibrary apply-load-rules all
[Switching to process 1413 thread 0x0]
warning: Unable to restore previously selected frame.
(gdb) 

and getting stuck at line +(int) factorial:(int) n at the @implementation resulting EXC_BAD_ACESS.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:19:47+00:00Added an answer on June 3, 2026 at 1:19 am

    I am not familiar with ObjC, but lines:

    +(int) factorial:(int)n
        //...
        return [self factorial:n]*[self factorial:n-1];
        //                      ^
    

    look suspicious for me. It means that for n != 0 you will get endless recursion and face stack overflow 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#import<Foundation/Foundation.h><br/> #import QuestionItem.h int main (int argc, const char * argv[]) { NSAutoreleasePool *
//SomeObject.h #import <Foundation/Foundation.h> @interface SomeObject : NSObject { } @property NSInteger aProperty; @end //main.m
New to objective-C, #import <objc/objc.h> #import <Foundation/Foundation.h> @interface Test:NSObject { int x,y, abc; NSString
operator class: #import <Foundation/Foundation.h> @interface operator : NSObject { int number; } @property int
Code: LotteryEntry.h #import <Foundation/Foundation.h> @interface LotteryEntry : NSObject { NSCalendarDate *entryDate; int firstNumber; int
I created a simple Person.h class: #import <Foundation/Foundation.h> @interface Person : NSObject { int
Error: Accessing unknown getter method? Thanks... #import <Foundation/Foundation.h> @interface puppy : NSObject { int
I've got this code: Entry.h #import <Foundation/Foundation.h> @interface Entry : NSObject { id object;
Below is my code: First Category.h #import <Foundation/Foundation.h> @interface Category : NSObject { NSMutableArray
#import <Foundation/Foundation.h> #import Dropbox_Manager.h @interface FileSystemManager : NSObject { NSFileManager *fileManager; BOOL fileExisting; BOOL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.