- Esecutori
-
Impara
Impara Python Esempi eseguibili, NumPy, pandas e altro Impara l'IA / Machine LearningReti neurali, ML e LLM da zero Impara C e C++ Puntatori, memoria, STL e C++ moderno Impara C#Fondamenti, OOP, LINQ, async ed esercizi .NET Impara MatplotlibGrafici a linee, barre, dispersione e torta con visualizzatori Impara RustOwnership, trait, gestione degli errori e thread Impara GoSlice, interfacce, goroutine e canali Algoritmi Python Ricerca, ordinamento, ricorsione e visualizzazioni O(n) Algoritmi C e C++ Confronta le implementazioni in C e C++ Programmazione per bambini Impara a programmare giocando!
- QuizNuovo
- SfideNuovo
- Per docentiNuovo
- Aggiornamenti
- Offrimi un caffè
Quiz di C: Strings & the Null Terminator
In C a string is just a char array that ends with a null character, '\0'. This quiz checks how that terminator affects sizeof, strlen and printf, and the classic mistakes with string literals.
Domanda di esempio
Domanda 1 di 10What does this print?
#include <stdio.h>
#include <string.h>
int main(void) {
char s[] = "hello";
printf("%zu %zu\n", sizeof(s), strlen(s));
return 0;
}
Mostra la risposta
D. 6 5 The array gets room for the 5 letters plus the terminating '\0', so sizeof(s) is 6. strlen counts characters before the terminator, so it is 5.
Cosa copre questo quiz
- The hidden
'\0'at the end of every string literal sizeofvsstrlen- Ending a string early by writing
'\0' - Characters are small integers
- Why string literals must not be modified
Domande frequenti
Serve un account?
No. Chiunque può giocare. Accedi per salvare XP, serie, badge e cronologia.
Posso rifarlo?
Sì. Il tuo miglior punteggio resta salvato, e domande e risposte vengono mescolate ogni volta.