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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:25:10+00:00 2026-05-25T03:25:10+00:00

This code: int p = 10; void *q; *q = 10; Does not compile:

  • 0

This code:

int p = 10;
void *q;
*q = 10;

Does not compile:

‘=’ : cannot convert from ‘int’ to ‘void *’

However, this code compiles fine:

int p = 10;
void *q;
q = &p;

What is the reason behind it?

  • 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-25T03:25:11+00:00Added an answer on May 25, 2026 at 3:25 am

    A void * points to data of an unknown type (if it is initialized, which yours is not).

    You can only assign to variables of a known type, or via pointers of a known type.

    int p = 10;
    void *q = &p;
    
    *(int *)q = 20;
    
    if (p != 20)
        ...something has gone horribly wrong...
    

    This converts the void * into an int * and then assigns a value to that dereferenced integer pointer.

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

Sidebar

Related Questions

This code does not compile. public class Diamond { public static void diamondOfAsterisks(String *
The following code does not compile ... any idea why? Is this illegal C++?
The following code does not compile: public class GenericsTest { public static void main(String[]
The following code does not compile. int a = 1, b = 2, c
Why this code does not compile: #include <boost/mpl/vector.hpp> #include <boost/mpl/for_each.hpp> #include <iostream> using namespace
Consider this code: int main() { int e; prn(e); return 0; } void prn(double
Consider this code: void res(int a,int n) { printf(%d %d, ,a,n); } void main(void)
I got this C code. #include <stdio.h> int main(void) { int n, d, i;
Given this piece of code: (void)someFunction(void) { int array[] = {1,2,3,4,5,6,7,8,9,10}; } Where are
Any idea why this code: extern C __declspec(dllexport) void Transform(double x[], double y[], 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.