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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:19:59+00:00 2026-05-31T19:19:59+00:00

I was trying to make an array-based linear list, then I compiled this: char

  • 0

I was trying to make an array-based linear list, then I compiled this:

char size = 0;
char testarray[10];

int main() { 
    add('a'); add('b'); add('c');
    add('d'); add('e'); add('f');
    add('g'); add('h'); add('i');
    add('j'); add('k'); add('l');
    add('m'); add('n'); add('o');
    print();
    return 0;
} 

void add(char newchar) {
    testarray[++size] = newchar;
}

void print() {
    char i = 0;
    for (i = 0; i <= size; i++) {
        printf("%c ", testarray[i]);
    }
 }

And compiled it with gcc arraytest.c but the array works just fine. Does that mean arrays are variable-length by default? I thought it was a C99-only feature.

It was compiled under both Gentoo (gcc version 4.5.3 (Gentoo 4.5.3-r2 p1.1, pie-0.4.7) and Ubuntu (gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3).

Oh, and isn’t this a bit dangerous?

  • 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-05-31T19:20:00+00:00Added an answer on May 31, 2026 at 7:20 pm

    So long as you are within your allocated range for your application you can use pointers/address wherever you want. keep going far enough and you either trash your program or hit the edge of your allocated memory and get a protection fault of some sort. Runtime checking is expensive, wouldnt want to have that anyway.

    swap your two variables

    char testarray[10];
    char size = 0;
    

    and see what happens when you run it…

    And then do this:

    char size = 0;
    char testarray[10];
    char stuff[10];
    

    before you start adding things to testarray, initialize stuff, then after doing your thing print out the stuff[] array. You should see your overflow. In C it is a good rule to put your non-array variables first in the assignment list and the array or arrays last, you have a better chance at debugging.

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

Sidebar

Related Questions

I have spent days trying to make this work based on the examples in
I'm trying to make a dynamic array in C# but I get an annoying
I'm writing some error checking and trying to make use of an boolean array
I'm trying to subclass Array in ruby to make it randomize its elements when
Trying to make a make generic select control that I can dynamically add elements
Trying to make a MySQL-based application support MS SQL, I ran into the following
My problem is I'm trying to make a console based chess game. Starting off
I'm trying to make a script that outputs user names based on weather they
I'm trying to make my first App. based on OpenGl, i'm trying to draw
I have a TextView that I am trying to make display a 2d character-based

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.