Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda