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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:17:52+00:00 2026-05-24T10:17:52+00:00

Here is a C code snippet char *p=Hello World; int a; char b; printf(%d\n,sizeof(p++));

  • 0

Here is a C code snippet

char *p="Hello World";
int a;
char b;
printf("%d\n",sizeof(p++));
printf("%c\n",*p);

printf("%d",sizeof(a,b));
printf("%d",sizeof(b,a));

Here is the output

4
H
1
4

Can anybody explain why p didn’t get incremented and what is the use of comma operator here. I read that it has something to do with VLAs.

  • 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-24T10:17:53+00:00Added an answer on May 24, 2026 at 10:17 am

    p didn’t get incremented because sizeof does not evaluate its operand, it just uses the type of the expression.

    sizeof is an operator taking a single expression as its operand, not a parenthesized argument list. So, in sizeof(a,b), the single operand is (a,b). The comma in sizeof(a,b) therefore is the comma operator — unlike the comma in printf("%c\n", *p), which is an argument separator and not the comma operator.

    When evaluated, the comma operator first evaluates its left-hand side, then evaluates the right-hand side. The result of the operator is the result of the right-hand side. So, although (a,b) isn’t evaluated, the type of the expression is the type of the right-hand side. Hence sizeof(a,b) is equivalent to sizeof(b). Really there’s no “use” of the comma operator here, at least no useful use. It’s pointless other than to test your ability to read it.

    It has nothing to do with VLAs (variable-length arrays).

    What does have to do with VLAs is that when sizeof is applied to a VLA, it is defined to evaluate the expression (6.5.3.4/2 in C99). The size of a VLA is of course not known at compile-time.

    But, when used on the RHS of a comma operator, the name of a VLA decays to a pointer just like any other array does. This is 6.3.2.1/3: there are three cases where an array does not decay, and “the operand of sizeof” is one of them but “the RHS of a comma operator” is not. So:

    #include <stdio.h>
    int main() {
        int a = 10;
        int b[a]; // VLA
        const char *p = "Hello";
        printf("%d\n", sizeof(++p, b));
        printf("%d\n", sizeof b);
        printf("%c", *p);
    }
    

    prints (on my machine):

    4
    40
    H
    

    because in the first sizeof, even though there’s a VLA on the RHS of the comma operator, the type of the operand of sizeof is int*, not a VLA, and so (++p, b) is not evaluated. In the second sizeof, the type of the operand is a VLA, which is evaluated, and its size is 10*sizeof(int).

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

Sidebar

Related Questions

Here is the code snippet: int main() { char ch=26; ofstream fout; fout.open(key.txt); if
Here's the code snippet: public static void main (String[]arg) { char ca = 'a'
here is the relevent code snippet: public static Rand searchCount (int[] x) { int
There is a code snippet, int matchhere(char *regexp, char *text) { /* do sth
Can u Give solution for this code of typecasting, LPCTSTR(here lpsubkey) to Char* for
I found this code snippet here , but I just can't figure out what
Here is my code snippet main() { char *filename; if(1 > 2) { filename
Here's the code snippet: float pNum = 9.2; char* l_tmpCh = new char[255]; sprintf_s(l_tmpCh,
Here is a code snippet for an asp:Wizard control I have on an aspx
Replaces Question: Update multiple rows into SQL table Here's a Code Snippet to update

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.