Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:11:53+00:00 2026-06-18T12:11:53+00:00

I read the 6.3th paragraph of the C programming language second edition, by Kernigan

  • 0

I read the 6.3th paragraph of the “C programming language” second edition, by Kernigan & Ritchie.

Some structure:

struct key {
    char *word;
    int count;
} keytab[NKEYS] {
    { "auto", 0 },
    { "break", 0 },
    { "case", 0 },
    { "char", 0 },
    { "const", 0 },
    { "continue", 0 }
  };

Authors wrote about it:

The quantity NKEYS is the number of keywords in keytab. Although we
could count this by hand, it’s a lot easier and safer to do it by
machine, especially if the list is subject to change. One possibility
would be to terminate the list of initializers with a null pointer,
then loop along keytab until the end is found.

Everything would be clear if enum contained pointers only:

struct key {
    char *word;
    char *description;
} keytab[NKEYS] {
    { "auto", "" },
    { "break", "" },
    { "case", "" },
    { "char", "" },
    { "const", "" },
    { "continue", "" }
    { NULL, NULL}
  };

But the each record has not pointer only, but and int too. If I am right understand authors, then a last record must be like following:

{ NULL, ? }

What about not pointers?

How can I solve it for enums, which don’t contain the pointers? For example:

    enum myEnum {
        int index;
        inr count;
        double value;
    } myVariable[] {
          {0,0,0},
          {0,0,0},
          {0,0,0},
          {0,0,0},
          {?,?,?}
      };

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:11:54+00:00Added an answer on June 18, 2026 at 12:11 pm

    The point is that by setting the last record to be NULL you can trivially identify the end of the array when iterating through it.

    In cases where you don’t have pointers, you could still deem some “special” value to indicate the end, perhaps count and index can never be negative in your application, so seeing a value less than 0 would be a possible marker that you can use to find the end reliably. Another common choice for end markers might be ~0 (i.e. all 1s).

    Alternatively you could just pass a size_t around with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Read (skimmed enough to get coding) through Erlang Programming and Programming Erlang . One
I read a text file to get some info from it and later on
Read some texts about locking in PHP. They all, mainly, direct to http://php.net/manual/en/function.flock.php .
I've read some questions here about this: This is good function(a, b) { a
Read some other things on here re: this similar problem but am not sure
A read some posts here and google and don´t find a substancial answer. Supose
read.cpp #include <iostream> #include <fstream> using namespace std; int main(void) { int id; char
I read somewhere that the switch statement uses Binary Search or some sorting techniques
Read some code from a legecy system. Say I have a instance of class
Read the edit below for more information. I have some code below that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.