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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:55:39+00:00 2026-06-16T21:55:39+00:00

#include <stdio.h> main() { char * ptr; ptr = hello; printf(%p %s ,hello,ptr );

  • 0
#include <stdio.h>

main()
{
  char * ptr;

  ptr = "hello";


  printf("%p %s" ,"hello",ptr );

  getchar();

}

Hi, I am trying to understand clearly how can arrays get assign in to pointers. I notice when you assign an array of chars to a pointer of chars ptr="hello"; the array decays to the pointer, but in this case I am assigning a char of arrays that are not inside a variable and not a variable containing them “, does this way of assignment take a memory address specially for "Hello" (what obviously is happening) , and is it possible to modify the value of each element in “Hello” wich are contained in the memory address where this array is stored. As a comparison, is it fine for me to assign a pointer with an array for example of ints something as vague as thisint_ptr = 5,3,4,3; and the values 5,3,4,3 get located in a memory address as “Hello” did. And if not why is it possible only with strings? Thanks in advanced.

  • 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-16T21:55:40+00:00Added an answer on June 16, 2026 at 9:55 pm

    "hello" is a string literal. It is a nameless non-modifiable object of type char [6]. It is an array, and it behaves the same way any other array does. The fact that it is nameless does not really change anything. You can use it with [] operator for example, as in "hello"[3] and so on. Just like any other array, it can and will decay to pointer in most contexts.

    You cannot modify the contents of a string literal because it is non-modifiable by definition. It can be physically stored in read-only memory. It can overlap other string literals, if they contain common sub-sequences of characters.

    Similar functionality exists for other array types through compound literal syntax

    int *p = (int []) { 1, 2, 3, 4, 5 };
    

    In this case the right-hand side is a nameless object of type int [5], which decays to int * pointer. Compound literals are modifiable though, meaning that you can do p[3] = 8 and thus replace 4 with 8.

    You can also use compound literal syntax with char arrays and do

    char *p = (char []) { "hello" };
    

    In this case the right-hand side is a modifiable nameless object of type char [6].

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

Sidebar

Related Questions

#include <stdio.h> int main() { char a[] = hello; char *ptr = a; printf
#include<stdio.h> main() { char c = 'R'; printf(%c\n,c); c++; printf(%c\n,c); char *ptr =Ramco Systems;
#include<stdio.h> int main() { static char *s[]={black,white,pink,violet}; char **ptr[]={s+3,s+2,s+1,s},***p; char a[]={DEAD}; p=ptr; ++p; printf(%c\n,a[0]);
#include <stdio.h> int main(void) { int x = 1000; char *ptr = &x; printf(%d\n,*ptr);
#include<stdio.h> int main (void) { int i=257; int *ptr=&i; printf(%d%d,*((char*)ptr),*((char*)ptr+1)); return 0; } Will
#include <stdio.h> int main() { char read = ' '; while ((read = getchar())
#include<stdio.h> int main() { char a[5]=hello; puts(a); //prints hello } Why does the code
hi can anybody tell me the error in this? #include<stdio.h> int main() { char
The program is: #include <stdio.h> #include <stdlib.h> int main(void) { char *a=abc,*ptr; ptr=a; ptr++;
Here is my sample code #include<stdio.h> void main() { int arr[]={1,2,3,4,5,6}; char *ptr,a; a='c';

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.