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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:12:40+00:00 2026-06-04T13:12:40+00:00

I am getting segmentation fault error for argc argument. I am new to C

  • 0

I am getting segmentation fault error for argc argument. I am new to C language. Please help me to solve this.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    int row1, row2, col1, col2, i, j, cnt=0;
    int mat1[2000][2000], mat2[2000][2000];

    printf("argc=%d", argc);

    if (argc<5)
    {
    printf("\nPlease enter correct arguments <row_no_matrix1> <col_no_matrix1> <row_no_matrix2> <col_no_matrix2>\n");
    exit(0);
    }

    row1 = atoi(argv[1]);
    col1 = atoi(argv[2]);
    row2 = atoi(argv[3]);
    col2 = atoi(argv[4]);

    printf("%d %d %d %d\n", row1, row2, col1, col2);
    return 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-04T13:12:42+00:00Added an answer on June 4, 2026 at 1:12 pm

    Your matrices are too big for the stack on your machine. Each of the arrays has 4 million integers, or roughly 16 MiB of storage; that is a very big stack requirement.

    Either reduce their size or allocate them dynamically.

    Or (as noted in the comments), make them into variables with ‘static duration’, either within main with the keyword static in front:

    int main(int argc, char *argv[])
    {
        int row1, row2, col1, col2, i, j, cnt=0;
        static int mat1[2000][2000], mat2[2000][2000];
    

    or as file scope variables defined outside main(), also with the keyword static in front:

    static int mat1[2000][2000], mat2[2000][2000];
    
    int main(int argc, char *argv[])
    {
        int row1, row2, col1, col2, i, j, cnt=0;
    

    or as global variables defined outside main() without the keyword static (but only do this if you will have multiple source files that need to access them by name):

    int mat1[2000][2000], mat2[2000][2000];
    
    int main(int argc, char *argv[])
    {
        int row1, row2, col1, col2, i, j, cnt=0;
    

    You could also (again, as noted in the comments) increase the stack size. However, I respectfully suggest that is probably the least satisfactory solution.

    How to dynamically allocate the size of an array?

    Fair question. How often do you think you’ll really need a pair of 4 million cell arrays, compared with how often will you be dealing with, say, under 100×100 arrays? Also, are you on Windows (with MSVC and C89) or non-Windows (with C99 or later), or on Windows with GCC?

    Also, have you learned about pointers yet?

    On the whole, I think you should opt for smaller size arrays. That is by far the simplest solution. If you must have big arrays, go with statically allocated arrays.

    If that won’t work, we’ll have to go through the pointers, but it isn’t pretty.

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

Sidebar

Related Questions

I am getting a Segmentation Fault error when running my program in GCC. This
I am getting a segmentation fault error when I run this code. I don't
I'm getting this error: Program received signal SIGSEGV, Segmentation fault. 0x0000000000407265 in Quadtree::deeper (this=0x7fffffffe430,
I am getting segmentation fault in this code but i cant figure out why.
Getting a segmentation fault for the following code. Please advise. struct columns { char*
I'm getting a segmentation fault everytime i want to run this code : from
Can you please tell me what I did wrong? I'm getting SIGSEGV (Segmentation fault)
I am getting the following error message: Program received signal SIGSEGV, Segmentation fault. 0x08048ff3
I am getting a Segmentation fault (core dumped) error when converting a PDF to
I am getting a segmentation fault while running this code. I can't work out

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.