Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

247
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!