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

  • SEARCH
  • Home
  • 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 3231850
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:05:35+00:00 2026-05-17T17:05:35+00:00

#include<stdio.h> int main(int argc,char *argv[]) { int i=10; void *k; k=&i; k++; printf(%p\n%p\n,&i,k); return

  • 0
#include<stdio.h>
int main(int argc,char *argv[])
{
   int i=10;
   void *k;
   k=&i;

   k++;
   printf("%p\n%p\n",&i,k);
   return 0;
}

Is ++ a legal operation on void* ? Some books say that it’s not
but K & R doesn’t say anything regarding void * arithmetic ( pg. 93,103,120,199 of K &R 2/e)

Please clarify.

PS : GCC doesn’t complain at least in k++.

  • 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-17T17:05:36+00:00Added an answer on May 17, 2026 at 5:05 pm

    It is a GCC extension.

    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.

    If you add the -pedantic flag it will produce the warning:

    warning: wrong type argument to increment

    If you want to abide to the standard, cast the pointer to a char*:

    k = 1 + (char*)k;
    

    The standard specifies one cannot perform addition (k+1) on void*, because:

    1. Pointer arithmetic is done by treating k as the pointer to the first element (#0) of an array of void (C99 §6.5.6/7), and k+1 will return element #1 in this “array” (§6.5.6/8).

    2. For this to make sense, we need to consider an array of void. The relevant info for void is (§6.2.5/19)

      The void type comprises an empty set of values; it is an incomplete type that cannot be completed.

    3. However, the definition of array requires the element type cannot be incomplete (§6.2.5/20, footnote 36)

      Since object types do not include incomplete types, an array of incomplete type cannot be constructed.

    Hence k+1 cannot be a valid expression.

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

Sidebar

Related Questions

#include stdio.h void Square(int num, int *myPointer); int main(int argc, const char *argv[]) {
#include <stdio.h> int main(int argc, char *argv[]) { long* fp; while(1) { fp =
#include<stdio.h> #include<zlib.h> #include<unistd.h> #include<string.h> int main(int argc, char *argv[]) { char *path=NULL; size_t size;
#include vss.h #include vswriter.h #include <VsBackup.h> #include <stdio.h> #define CHECK_PRINT(result) printf(%s\n,result==S_OK?S_OK:error) int main(int argc,
#include <stdio.h> int main() { float a = 1234.5f; printf(%d\n, a); return 0; }
#include<stdio.h> int main() { int a,b; a=a+b; printf(%d,a); return 0; } what should be
stattest.c: // compile: gcc -o stattest stattest.c #include <stdio.h> #include <sys/stat.h> int main(int argc,
The following C++ program compiles and runs as expected: #include <stdio.h> int main(int argc,
#include<stdio.h> int main() { printf(He %c llo,65); } Output: He A llo #include<stdio.h> int
#include <stdio.h> int main() { char read = ' '; while ((read = getchar())

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.