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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:31:32+00:00 2026-06-17T13:31:32+00:00

The following code is segfaulting on me. #include <stdio.h> int main(int argc, char **argv)

  • 0

The following code is segfaulting on me.

#include <stdio.h>

int main(int argc, char **argv)
{
    const int MEMSIZE = 1024*1024*10;
    char memblock[MEMSIZE];
    memblock[10] = '\0';

    printf("%s", memblock);

    return 0;
}

Is there some size limit on character arrays? I’ve forgotten all my C, am I doing something stupid here?

  • 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-17T13:31:33+00:00Added an answer on June 17, 2026 at 1:31 pm

    There’s no limit on the size of char arrays as such but stack sizes will be relatively constrained compared to available heap memory. You’re probably overflowing the stack here. You could try making memblock static

    static char memblock[MEMSIZE];
    

    or allocating it dynamically

    char* memblock = malloc(MEMSIZE);
    if (memblock == NULL) {
        printf("Error: failed to allocate %d byte buffer\n", MEMSIZE);
        return -1;
    }
    memblock[10] = '\0';
    printf("%s", memblock);
    free(memblock);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following code doesn't throw exception and prints success. Why ? #include <iostream> int main()
Following code will compile but crash at run time: int main() { try {
Following code is in simplest form: struct X { operator char () const {
following code for partition #include<iostream> using namespace std; #define maxn 10000 int x[maxn]; void
I have the following code: int get_int(void) { char input[10]; fgets(input, 10, stdin); //
Following code return this error: main.cpp|80|error: passing ‘const matrix’ as ‘this’ argument of ‘T&
Following code is giving compilation error in visual studio 2009. #include <iterator> #include <vector>
following code behaves strange (at least for me): int testValue = 1234; this.ConversionTest( testValue
Following code is in my c++ class static const QString ALARM_ERROR_IMAGE ; i want
Following code generate no compilation/linker error/warning: // A.h #include<iostream> struct A { template<typename T>

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.