# include<stdio.h>
void main()
{  int p;
    p = (1,2,2,100,1);
    printf("%d",p);
}

I dont know what will be the output . Can anyone please tell me what exactly second line implies ?? :rolleyes:

comma ' , ' operator has left to right associativity

# include<stdio.h>
void main()
{  int p;
    p = 1,2;
    printf("%d",p);
}

In this case output will be 1

But if we apply ( )
then last value is assigned to p and output will be 2

# include<stdio.h>
void main()
{  int p;
    p = (1,2,2,100,1);
    printf("%d",p);
}

I dont know what will be the output . Can anyone please tell me what exactly second line implies ?? :rolleyes:

though p should be declare as an array int p[]

if p were an array, then the initializer list would have to be in braces, not parentheses, like this

int p[] = {1,2,2,100};

But the above is entirely different than the code you originally posted.

># include<stdio.h>
>void main()
>{ int p;
> p = 1,2;
> printf("%d",p);
>}
>In this case output will be 1

what will be the output, if i make a bit of change in the existing code, i mean:::

# include<stdio.h>
void main()
{ int p = 1,2;
printf("%d",p);
}

i got error in this case, i dont know , why its producing error in this case, when it looks similar to the old one?? :?:

parentheses are required as shown in previous posts.

The same..
Paranthesis will do the work for getting p=(1,2)
so o/p will be 2.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.