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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:15:06+00:00 2026-05-14T02:15:06+00:00

Yesterday in my interview I was asked this question. (At that time I was

  • 0

Yesterday in my interview I was asked this question. (At that time I was highly pressurized by so many abrupt questions).

int *p;
*p=23;
printf("%d",*p);

Is there any problem with this code?

I explained him that you are trying to assign value to a pointer to whom memory is not allocated.

But the way he reacted, it was like I am wrong. Although I got the job but after that he said Mohit think about this question again.
I don’t know what he was trying to say. Please let me know is there any problem in my answer?

EDIT
I added the code on the sheet;-

int *p;
p=malloc(sizeof(int));
*p=23;
printf("%d",*p);      

This must be the perfect code…Am i right..

EDIT2

int *p;
*p=23;
 OR
int *p=23;

I think both has problem. Cause some body is saying about the title of the post.

  • 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-14T02:15:07+00:00Added an answer on May 14, 2026 at 2:15 am

    “trying to assign value to a pointer to whom memory is not allocated”

    I think you just misphrased it a bit. You’re not trying to assign a value to a pointer, you’re trying to assign a value to the referand of a pointer.

    Since the pointer is uninitialised, this is, as you say, undefined behaviour. The pointer doesn’t refer to anything (at least not validly – as other answers point out, the bits of storage of p might just so happen to contain a value which is the address of some memory location, and your code might overwrite that. The standard permits anything to happen with UB, but knowing something about your implementation you can often take a shrewd guess).

    So probably in the interviewer’s mind you have the right idea, but it’s valuable to have it exactly straight in your mind and in your speech what the difference is between a finger and the moon, and which one you’re talking about.

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

Sidebar

Related Questions

this is an interview question my friend was asked yesterday. The question was something
I had telephone interview question yesterday. The interviewer asked me if I had faced
Yesterday, I asked this question and never really got an answer I was really
Had this question in the interview yesterday. Which is better to use? Infix(with parenthesis)
I got this question today in an interview: write a function to calculate the
Yesterday i had a question in an interview which i thought i could find
Was asked in an interview yesterday to name three good and three bad things
Yesterday I asked this post , but I am still having problems when I
Yesterday I wanted to add a boolean field to an Oracle table. However, there
Yesterday, I discovered the Subversion (SVN) blame feature, and I was wondering, is this

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.