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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:36:16+00:00 2026-06-14T15:36:16+00:00

In the following example: int *i; *i=1; it produces a program to hang, because

  • 0

In the following example:

int *i;
*i=1;

it produces a program to hang, because I know that I am putting a value directly to a memory position.

The question that I have is why the following:

int *i=1;

only produces a warning related to a casting of an integer and does not hang the program?

and why this instruction does not produce not an error nor a warning?

char *s="acd";

if I am using something similar to the example before

Thanks

  • 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-14T15:36:17+00:00Added an answer on June 14, 2026 at 3:36 pm

    Let’s talk about the 3 cases individually:

    int *i;
    *i=1;
    

    The first line allocates memory for a pointer, but does not initialize it, leaving i with a random garbage value. The second line tries to write to the memory address spelled out by the random garbage, causing undefined behaviour at runtime.

    int *i=1;
    

    This allocates memory for a pointer and assigns it the value 1 (i.e. the memory address 0x1). Since this implicitly casts the integer value 1 to a pointer, you get a warning, since it’s extremely rare to ever initialize a pointer to a non-null memory address.

    As an aside, if you were to do:

    int *i=1;
    *i=1;
    

    it would try to write the value 1 to the memory address 0x1, causing the same undefined behaviour as in your first case.

    char *s="acd";
    

    This creates a null-terminated string on the stack and makes s point to it. String literals are the natural thing to assign to a char *, so no warning.

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

Sidebar

Related Questions

Consider the following example program: next :: Int -> Int next i | 0
Consider the following example: int size = 10, *kk = new int[size]; for (int
I want to use rb_require with rb_protect, as in the following example: int error;
I have the following example, compiled in VS2005, warning level 4: int main(int argc,
Say, there is a following example: class Super { public int i = 3;
Example: For(int i=0; i<4; i++) playSound(Sound.wav); I have the following classes: Main import java.io.IOException;
Take the following C code as an example: char buffer1[5]; int* ret; printf(Buffer1 is:
Example: Suppose in the following example I want to match strings that do not
I need help explaing the following example below (c) CommonsWare. I know it makes
I've reduced my problem down to the following example code: class pokemon{ public: pokemon(int

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.