- Ejecutores
-
Aprender
Aprender Python Ejemplos ejecutables, NumPy, pandas y más Aprender IA / Machine LearningRedes neuronales, ML y LLM desde cero Aprender C y C++ Punteros, memoria, STL y C++ moderno Aprender C#Fundamentos, POO, LINQ, async y ejercicios de .NET Aprender MatplotlibGráficos de líneas, barras, dispersión y sectores con visualizadores Aprender RustOwnership, traits, manejo de errores e hilos Aprender GoSlices, interfaces, goroutines y canales Algoritmos en Python Búsqueda, ordenación, recursión y visualizadores O(n) Algoritmos en C y C++ Compara implementaciones en C y C++ Programación para niños ¡Aprende a programar jugando!
- QuizzesNuevo
- RetosNuevo
- Para docentesNuevo
- Actualizaciones
- Invítame a un café
Quiz de C: Memory Bugs
Manual memory management is where most serious C bugs come from. This hard quiz shows short programs with leaks, double frees, dangling pointers and buffer overruns, and asks you to name the bug and the fix, just like a code review or a C interview.
Pregunta de ejemplo
Pregunta 1 de 10What is wrong with this code?
#include <stdio.h>
#include <stdlib.h>
int main(void) {
for (int i = 0; i < 3; i++) {
char *buf = malloc(64);
if (buf == NULL) return 1;
snprintf(buf, 64, "line %d", i);
printf("%s\n", buf);
}
return 0;
}
Ver la respuesta
C. Memory leak: each buf is never freed Every iteration allocates a new block and loses the pointer at the end of the loop body, so three blocks leak. Add free(buf); after the printf(), or allocate once before the loop.
Qué cubre este quiz
- Memory leaks in loops and when a pointer is overwritten
- Use after free and dangling pointers
- Double free and freeing memory that was not allocated
- Off-by-one allocations for strings
- Tools that catch these bugs at runtime
Preguntas frecuentes
¿Necesito una cuenta?
No. Cualquiera puede jugar. Inicia sesión para guardar tu XP, racha, insignias e historial.
¿Puedo repetirlo?
Sí. Se guarda tu mejor puntuación, y las preguntas y respuestas se mezclan cada vez.