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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:16:01+00:00 2026-06-13T12:16:01+00:00

int main() { int a; void *p; p = &a; printf(%ld\n,(long)p); p = p+1;

  • 0
int main()  
{  
    int a;  
    void *p;  
    p = &a;  
    printf("%ld\n",(long)p);  
    p = p+1;  
    printf("%ld\n",(long)p);  
}  

In this program, p+1 is just incrementing the value of p by 1. I know void pointer arithmetic is not possible in C, so GCC is doing it implicitly. And if yes, then is it taking it as char pointer. Also, why dereferencing is not possible for void pointer, if it is implicitly doing pointer arithmetic.

  • 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-13T12:16:02+00:00Added an answer on June 13, 2026 at 12:16 pm

    C does not allow pointer arithmetic with void * pointer type.

    GNU C allows it by considering the size of void is 1.

    From 6.23 Arithmetic on void- and Function-Pointers:

    In GNU C, addition and subtraction operations are supported on pointers to void and on pointers to functions. This is done by treating the size of a void or of a function as 1.

    http://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

    Now to answer this question:

    Also, why dereferencing is not possible for void pointer, if it is implicitly doing pointer arithmetic.

    GNU C allows pointer arithmetic with void * but still does not allow an object of type void to be declared.

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

Sidebar

Related Questions

#include<stdio.h> void main(){ int x,y,z; x=y=z=1; z=++x||++y&&++z; printf(%d %d %d \n,x,y,z); getch(); } the
#include<stdio.h> void function(int); int main() { int x; printf(Enter x:); scanf(%d, &x); function(x); return
consider the code #include<stdio.h> int main(void) { char* a; scanf(%s,a);//&a and &a[0] give same
void foo(ifstream &ifs) { //do something } int main() { fstream fs(a.txt, fstream::in); foo(fs);
template <typename T> void f(T&) {} template <typename T> void f(T&&) {} int main()
I have the following code int main() { int a=6; void *p; p=&a; p++;
int main(void) { char testStr[50] = Hello, world!; char revS[50] = testStr; } I
int main(void) { std::string foo(foo); } My understanding is that the above code uses
int main(void) { int* p = (int*) malloc(sizeof(int)); int* q = (int*) malloc(sizeof(int)); *p
int main(void) { char *p = hello; char *q = world; *p = *q;

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.