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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:42:17+00:00 2026-06-14T10:42:17+00:00

The foll basic code on gcc compiler outputs 3. But when I replace the

  • 0

The foll basic code on gcc compiler outputs 3.

But when I replace the {} by () then it outputs 4

     int i={3,2,4};printf("%d",i); 

Can someone explain this behaviour? The , operator follows left to right evaluation but it doesn’t in case of {}.

  • 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-14T10:42:18+00:00Added an answer on June 14, 2026 at 10:42 am

    When you use {3,2,4} you are using scalar initialization, but you are providing more elements than what you should. This will trigger a warning by the compiler, but yeah it will both compile and execute, and the first element on the scalar initialization will be attributed to the variable i.

    When you use (3,2,4) you are basically using the comma operator (the parentheses are needed because you are initializing the variable). The comma operator evaluates the first operand and discards the result, then evaluates the second operand and returns the result. So here you evaluate 3, discard it, then evaluate 2, return it (this return value is used as left operand of the second comma) and finally evaluate 4, and return it, so the 4 is attributed to the variable i.

    Here’s another interesting operation:

    int i;
    i = 3,4;
    printf("%d\n",i);
    

    This will print 3, because first i=3 will be evaluated (as this is left operand of the comma), and its result will be discarded. Then 4 will be evaluated and its result returned, but not attributed to the variable.

    And to make things more interesting:

    int i,j;
    j = (i = 3,4);
    printf("%d %d\n",i,j);
    

    This will print “3 4”. In other words, everything that I described above will happen, but when the 4 is evaluated and returned it will now be attributed to j.

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

Sidebar

Related Questions

ViewModelA: inside its constructor (breakpoint hits the foll. line): Messenger.Default.Register<int>(this, token, OnHitIt); ViewModelB: breakpoint
I have the foll line of code. int i =125; char s[]=hello; char c='z';
This question is a continuation of Malloc call crashing, but works elsewhere I tried
When I type in the foll. code, I get the output as 1073741823. #include
I am executing the foll code in Firefox it works fine i am basically
I have the foll xml can anyone please guide me how can i render
I'd the foll. requirement for one of my web applications: In my HTML table,
I'm drawing an Image on the canvas using the drawImage function. This is how
I have the foll prog class Person { var $name; function Person () {
While compiling a C program in LINUX, I get the foll. error: stream.h:1123: error:

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.