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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:42:18+00:00 2026-06-02T16:42:18+00:00

I want to convert the type of the pointer ‘p’. Begining ,the type of

  • 0

I want to convert the type of the pointer ‘p’. Begining ,the type of the pointer p is void .After allocating four bytes of memory for it, I cast pointer type into ‘int’,However ,this doesn’t work . maybe the sentence p=(int *)p doesn’t work.
Please tell me why and solve the problem.thanks.
The coding:

#include<stdio.h>
#include <stdlib.h>

 int main(void)
{
   void *p;
   p=malloc(sizeof(int));
   if(p == NULL)
    {
        perror("fail to malloc");
        exit(1);
    }
    p=(int *)p;
        *p=100;
    printf("the value is : %d\n",*p);

    return 0;
 } 
  • 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-02T16:42:20+00:00Added an answer on June 2, 2026 at 4:42 pm

    You’ll have an easier time directly casting the void pointer returned by malloc to an int*

    #include<stdio.h>
    #include <stdlib.h>
    
    int main(void)
    {
       int *p;
       p = malloc(sizeof(int));
       if(p == NULL)
        {
            perror("fail to malloc");
            exit(1);
        }
    
        *p=100;
        printf("the value is : %d\n",*p);
    
        return 0;
     } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to convert an string to an enum type using TValue, I googled
I want to convert the items to a String array or the type that
I have a char type column in table. I want to convert it to
I am use next type of strings: LPCSTR, TCHAR, String i want to convert:
I want to convert a pointer *int to its real value int , in
For some complicated reason, I want to convert any supported type T (coming from
I want to convert pointers of any type to int in C and C++.
I have error: Cannot implicitly convert type 'string' to 'System.DateTime'a When I want get
I have a field that is type text and I want to convert it
I want to convert a string to formatted text in C# in WPF application,

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.