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 7184219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:09:19+00:00 2026-05-28T18:09:19+00:00

Given that these are allowed: char c[] = abc; char c[] = {‘a’,’b’,’c’,’\0′} char

  • 0

Given that these are allowed:

char c[] = "abc";
char c[] = {'a','b','c','\0'}
char *c = "abc";

Why then is this not allowed?

char *c = {'a','b','c','\0'};  // error: a char cannot initialize a char*

If a string literal is interpreted by the compiler as a null-terminated array of chars then I would have thought it equivalent to statement 3 above, no?

Similarly, why is this not allowed :

int arr[3];
int *i = arr; // OK
int *i = {1,2,3} // error: an int cannot initialize an int*

It’s not a huge problem, I’m just curious.. I guess the question boils down to what’s the difference between a string literal (or declared integer array) and an array of character elements when assigning to a pointer?

  • 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-05-28T18:09:20+00:00Added an answer on May 28, 2026 at 6:09 pm

    Arrays aren’t pointers. Initializing a character array with a string literal is a special case (6.7.8#14):

    An array of character type may be initialized by a character string literal, optionally enclosed in braces. Successive characters of the character string literal (including the terminating null character if there is room or if the array is of unknown size) initialize the elements of the array.

    and also (6.7.8#16):

    Otherwise, the initializer for an object that has aggregate or union type shall be a brace-enclosed list of initializers for the elements or named members.

    As to the pointer initialization (6.7.8#11):

    The initializer for a scalar shall be a single expression, optionally enclosed in braces. The initial value of the object is that of the expression (after conversion); the same type constraints and conversions as for simple assignment apply, taking the type of the scalar to be the unqualified version of its declared type.

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

Sidebar

Related Questions

This is not a technical question, but given that there are a few iPhone
First off, I'm embarassed that I don't know this. I know these things work,
I had a bug in my code that went like this. char desc[25]; char
Given that there are many sizes and color depths for different phones (even for
Original Problem: I have 3 boxes each containing 200 coins, given that there is
Given that I have a table that holds vehicle information and one of those
Is there a way to read a locked file across a network given that
What alternatives are there to GAE, given that I already have a good bit
Is there an easy way to verify that a given private key matches a
Is there any possibility that GetPropInfo returns nil even if the given class is

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.