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

243
Vistas
In C, Is it possible to create a string without '\0(null)'?

I mean, as far as I know, a string would 'end' when 'null value(\0)' appears.

And many functions have to do with string return value and escape as soon as it meets 'null value' in string.

But, what if there's no null value in string?

Is it even possible to create such string?

Like, is it possible to create an array

char cArray[100] ={};

and fill all the indexes out without 'null'?.

If so, what's the best way to 'indicate the end of string that doesn't have null value at all'?

Is it even 'a string' if there's no null in it?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Is it even possible to create such string?

You can have arrays of char without a zero element. Those are not strings.

Like, is it possible to create an array

char cArray[100]; // the original had the illegal initializer = {};

and fill all the indexes out without 'null'?.

Yes, that's perfectly reasonable (memset(cArray, '*', 100);). But cArray (or any part of it) will not be a string.

If so, what's the best way to 'indicate the end of string that doesn't have null value at all'?

If you want to work with sequences of bytes without an indicator, you need to keep count separately.

char NotAString[6] = "abcdef";
size_t n = 6;
// remove the 'f' from NotAstring
n = 5;
// remove the 'b'
memmove(NotAString + 1, NotAString + 2, 3);
n -= 1;
// the first `n` (4) bytes of NotAString are now 'a', 'c', 'd', and 'e'
// don't care about bytes 5 and 6

Is it even 'a string' if there's no null in it?

No.

over 4 years ago · Santiago Trujillo Denunciar

0

But, what if there's no null value in string?

Then it's not a string. A "string" is defined by 7.1.1 Definitions of terms, pararaph 1 in the (draft) C11 standard:

A string is a contiguous sequence of characters terminated by and including the first null character. The term multibyte string is sometimes used instead to emphasize special processing given to multibyte characters contained in the string or to avoid confusion with a wide string. A pointer to a string is a pointer to its initial (lowest addressed) character. The length of a string is the number of bytes preceding the null character and the value of a string is the sequence of the values of the contained characters, in order.

Without that "null character", the array is NOT a "string".

Full stop.

over 4 years ago · Santiago Trujillo Denunciar

0

You can totally have a char array without the null terminator (it is like an int array after all), but it is NOT a string (by definition) and you won't be able to use all the standard C functions related to strings since they all rely on the presence of the terminator.

In the end you would have to treat the array of characters as a generic array.

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