C++ The data type for a sentinel value is always a boolean? True or false?

1.4k views Asked by At

just started an introductory C++ course. I have a query as below.

The data type for a sentinel value is always a boolean? True or false?

3

There are 3 answers

0
Ben Voigt On

Let's look at an example of a sentinel value found in the Standard:

A null-terminated byte string, or NTBS, is a character sequence whose highest-addressed element with defined content has the value zero (the terminating null character); no other element in the sequence has the value zero.

But what type is this character sequence (and the value zero that ends it)?

A character sequence is an array object A that can be declared as T A [N], where T is any of the types char, unsigned char, or signed char, optionally qualified by any combination of const or volatile.

0
Siddhartha Ghosh On

Sentinel value need not necessarily be a boolean type, it depends on your program logic to determine what should be a best sentinel value/data type.

See some examples here:-

http://www.mikeware.us/cpp/?p=20.

0
P0W On

From wiki

Below are some examples of common sentinel values and their uses:

  • Null character for indicating the end of a null-terminated string
  • Null pointer for indicating the end of a linked list
  • A negative integer for indicating the end of a sequence of non-negative integers
  • End-of-file, a non-character value returned by certain input routines to signal that no further characters are available from a file
  • High Values, a key value of hexadecimal 0xFF used in business programming

So it all depends how you define "sentinel"