Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

87
Views
can we give the number of elements in an array as needed using a variable?
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int L[n];
    // ...
    return 0;
}

I'm asking if I can give the number of elements in an array as needed using a variable . The teacher told us that this method is not recommended and I did not understand why. Thanks for answering for my question .

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This declaration

int L[n];

is a declaration of a variable length array. Variable length arrays are conditionally supported by compilers.

So it is not excluded that you can meet a compiler that does not support such declarations.

Pay attention to that in this declaration the value of the variable n shall be greater than 0.

As such an array has automatic storage duration then its size should not be vary big. Otherwise you should allocate memory for the array dynamically.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!