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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:20:29+00:00 2026-06-17T09:20:29+00:00

#include <stdio.h> int main(void){ char *p = Hello; p = Bye; //Why is this

  • 0
 #include <stdio.h>

  int main(void){

  char *p = "Hello";  
  p = "Bye";              //Why is this valid C code? Why no derefencing operator?

  int *z;
  int x;
  *z = x
  z* = 2                 //Works
  z  = 2                 //Doesn't Work, Why does it work with characters?

 char *str[2] = {"Hello","Good Bye"};

 print("%s", str[1]);      //Prints Good-Bye.     WHY no derefrencing operator?
                          // Why is this valid C code? If I created an array with pointers
                         // shouldn't the element print the memory address and not the string?
  return 0;

  }

My Questions are outlined with the comments. In gerneal I’m having trouble understanding character arrays and pointers. Specifically why I can acess them without the derefrencing operator.

  • 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-17T09:20:30+00:00Added an answer on June 17, 2026 at 9:20 am

    When you type “Bye”, you are actually creating what is called a String Literal. Its a special case, but essentially, when you do

    p = "Bye";
    

    What you are doing is assigning the address of this String literal to p(the string itself is stored by the compiler in a implementation dependant way (I think) ). Technically address to the first element of a char array, as Richard J. Ross III explains.

    Since it is a special case, it does not work with other types.

    By the way, you should likely get a compiler warning for lines like char *p = "Hello";. You should be required to define them as const char *p = "Hello"; since modifying them is undefined as the link explains.


    As to the printing code.

    print("%s", str[1]); 
    

    This doesnt need a dereferencing operation, since internally %s requires a pointer(specifically char *) to be passed, thus the dereferencing is done by printf. You can test this by passing a value when printf is expecting a pointer. You should get a runtime crash when it tries to dereference it.

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

Sidebar

Related Questions

#include <stdio.h> void wrapperPrint(char* s) { printf(s); return; } int main() { wrapperPrint(Hello world\n);
consider the code #include<stdio.h> int main(void) { char* a; scanf(%s,a);//&a and &a[0] give same
I got this C code. #include <stdio.h> int main(void) { int n, d, i;
For this code: #include<stdio.h> void hello() { printf(hello\n); } void bye() { printf(bye\n); }
#include <stdio.h> int main(void){ char x [] = hello world.; printf(%s \n, &x[0]); return
#include <stdio.h> #include <string.h> int main(void) { char *w; strcpy(w, Hello Word); printf(%s\n, w);
#include<stdio.h> void swap(char *, char *); int main() { char *pstr[2] = {Hello, IndiaBIX};
#include <stdio.h> #include <stdlib.h> void message(char m) { print(Hello\n); } int main() { message(m);
Given this code : #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main(void) { int
#include stdio.h int main (void) { char xx[1000] = hello; sprintf (xx, xyzzy plugh

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.