Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

89
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda