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

  • Home
  • SEARCH
  • 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 8329577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:50:18+00:00 2026-06-09T01:50:18+00:00

In C, you can partially initialize a struct or array, with the result that

  • 0

In C, you can partially initialize a struct or array, with the result that the members/elements that aren’t mentioned in the initializer are zero-initialized. (C99 section 6.7.8.19). For example:-

int a[4] = {1, 2};
// a[0] == 1
// a[1] == 2
// a[2] == 0
// a[3] == 0

You can also initialize “an array of character type” with a string literal (C99 section 6.7.8.14), and “successive characters … initialize the elements of the array”. For example:-

char b[4] = "abc";
// b[0] == 'a'
// b[1] == 'b'
// b[2] == 'c'
// b[3] == '\0'

All pretty straightforward. But what happens if you explicitly give the length of the array, but use a literal that’s too short to fill the array? Are the remaining characters zero-initialized, or do they have undefined values?

char c[4] = "a";
// c[0] == 'a'
// c[1] == '\0'
// c[2] == ?
// c[3] == ?

Treating it as a partial initializer would make sense, it would make char c[4] = "a" behave exactly like char c[4] = {'a'}, and it would have the useful side-effect of letting you zero-initialize a whole character array concisely with char d[N] = "", but it’s not at all clear to me that that’s what the spec requires.

  • 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-09T01:50:20+00:00Added an answer on June 9, 2026 at 1:50 am
     char c[4] = "a";
    

    All the remaining elements of the array will be set to 0. That is, not only c[1] but also c[2] and c[3].

    Note that this does not depend on the storage duration of c, i. e., even if c has automatic storage duration the remaining elements will be set to 0.

    From the C Standard (emphasis mine):

    (C99, 6.7.8p21) “If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.“

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

Sidebar

Related Questions

I've been playing around, partially reinventing wheels so that I can understand how proper
I was trying to solve a partially initialized sudoku puzzle (the kind that appears
How can Mercurial (or any other DVCS) recognize partially overlapped histories? E.g. fine grain
i can't run my wp7 app(https://github.com/slodge/face) on my device. I mean, app runs, partially.
I know that i can enter/add new properties via code manually into partial classes
How can I calculate year in a nullable date? partial void AgeAtDiagnosis_Compute(ref int result)
I've been reading over the internet about a partial method that I can use
I have a piece of code that can be executed by multiple threads that
I have been working on a form that presents some specific elements in a
I'm having an issue making an app that plays music in rails. I can't

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.