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 8261155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:18:21+00:00 2026-06-08T03:18:21+00:00

I have this simple program, when I run this program, I get segmentation fault,

  • 0

I have this simple program, when I run this program, I get segmentation fault, I can not
recognize where is my mistake. any help welcomed.(segmentation fault for Di>=27). The point
is that when I remove function immediately segmentation fault disappears. Or when I transform the function to a void function. I know there is a leak memory because not uses delete operator,
it causes leak memory,but easily is not responsible for segmentation fault(This leak memory is very far to produce segmentation fault).for simplicity I didn’t use delete operator.

 #include <iostream>
    #include<complex>
    using namespace std;
    const int Di=27;
    typedef struct {
         complex<double> Matrix[Di][Di][Di][Di];

        } O;

    O initializing(int );

    int main()
    {
    O * Operator=new O[1];
    int p;
    int n;
    Operator[0]=initializing(n);
    cout<<"hi";
    return 0;

    }



O initializing(int  point)
{
int i,j,m,n;
O *Operator=new O[1];
for(i=0;i<Di-1;i++)
    for(j=0;j<Di-1;j++)
        for(n=0;n<Di-1;n++)
            for(m=0;m<Di-1;m++)
            Operator[0].Matrix[i][j][m][n]=2;

            cout<<Operator[0].Matrix[Di-1][Di-1][Di-1][Di-1];
return Operator[0];


}
  • 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-08T03:18:23+00:00Added an answer on June 8, 2026 at 3:18 am

    You are returning a struct with a large array by value, and it does not fit on the stack. Return the struct by pointer, and dereference that pointer in the caller. It would help you avoid a memory leak, too.

    O* initializing(int );
    
    int main()
    {
        O * Operator=new O[1];
        int p;
        int n;
        O *tmp = initializing(n);
        Operator[0] = *tmp;
        delete[] tmp;
        cout<<"hi";
        return 0;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple test program that when I run I get: ./hello: error
I am receiving a Segmentation Fault error when I run this program. To summarize,
I have a very odd issue trying to run this quite simple C program
I have this simple program that computes salaries for four different worker types. It's
I have created this simple program to learn shared_ptr using namespace std; #define Yes
I have this simple example: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
My situation is simple. I have this in my program: File folder = new
I have this simple redirection on my website and it does not rewrite my
This one is probably very simple, but I can't seem to get it working.
I have this following simple service program: using System.Diagnostics; using System.ServiceProcess; namespace BasicService {

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.