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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:52:34+00:00 2026-05-31T00:52:34+00:00

As the heading says, What is the difference between char a[] = ?string?; and

  • 0

As the heading says, What is the difference between

char a[] = ?string?; and 
char *p = ?string?;  

This question was asked to me in interview.
I even dont understand the statement.

char a[] = ?string?

Here what is ? operator? Is it a part of a string or it has some specific meaning?

  • 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-31T00:52:35+00:00Added an answer on May 31, 2026 at 12:52 am

    The first one is array the other is pointer.

    The array declaration char a[6]; requests that space for six characters be set aside, to be known by the name a. That is, there is a location named a at which six characters can sit. The pointer declaration char *p; on the other hand, requests a place which holds a pointer. The pointer is to be known by the name p, and can point to any char (or contiguous array of chars) anywhere.

    The statements

     char a[] = "string";
     char *p = "string"; 
    

    would result in data structures which could be represented like this:

         +---+---+---+---+---+---+----+
      a: | s | t | r | i | n | g | \0 |
         +---+---+---+---+---+---+----+
         +-----+     +---+---+---+---+---+---+---+ 
      p: |  *======> | s | t | r | i | n | g |\0 |    
         +-----+     +---+---+---+---+---+---+---+ 
    

    It is important to realize that a reference like x[3] generates different code depending on whether x is an array or a pointer. Given the declarations above, when the compiler sees the expression a[3], it emits code to start at the location a, move three elements past it, and fetch the character there. When it sees the expression p[3], it emits code to start at the location p, fetch the pointer value there, add three element sizes to the pointer, and finally fetch the character pointed to. In the example above, both a[3] and p[3] happen to be the character l, but the compiler gets there differently.

    Source: comp.lang.c FAQ list · Question 6.2

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

Sidebar

Related Questions

I have a string like this: Heading Some interesting text here HeadingSome interesting text
What is the difference between: Ex 1. <script type=text/javascript> document.write(<h1>This is a heading</h1>); document.write(<p>This
Sorry I couldn't find the best heading for this question. Following is my requirement.
I have a text string structured like this: = Some Heading (1) Some text
As the heading says. I would like to know how can i do this
Heading Is there a way to map an arbitrary string to a HEX COLOR
Is there a difference between setting things for a mode using eval-after-load and using
Heading says it all really. Using Windows 7 and latest stable gvim, whenever I
See Wikipedia http://en.wikipedia.org/wiki/Css If you look at the heading, it says Cascading Style Sheets,
please help me with the website heading here. Please look at my picture below:

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.