Basic Concept

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2004
Posts: 68
Reputation: harshchandra is an unknown quantity at this point 
Solved Threads: 1
harshchandra harshchandra is offline Offline
Junior Poster in Training

Basic Concept

 
0
  #1
Sep 29th, 2005
  1. # include<stdio.h>
  2. void main()
  3. { int p;
  4. p = (1,2,2,100,1);
  5. printf("%d",p);
  6. }

I dont know what will be the output . Can anyone please tell me what exactly second line implies ?? :rolleyes:
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: Basic Concept

 
0
  #2
Sep 29th, 2005
comma ' , ' operator has left to right associativity

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

But if we apply ( )
then last value is assigned to p and output will be 2
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 3
Reputation: keevin is an unknown quantity at this point 
Solved Threads: 0
keevin keevin is offline Offline
Newbie Poster

Re: Basic Concept

 
0
  #3
Sep 30th, 2005
Originally Posted by harshchandra
  1. # include<stdio.h>
  2. void main()
  3. { int p;
  4. p = (1,2,2,100,1);
  5. printf("%d",p);
  6. }

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[]
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,494
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Basic Concept

 
0
  #4
Sep 30th, 2005
if p were an array, then the initializer list would have to be in braces, not parentheses, like this
  1. int p[] = {1,2,2,100};

But the above is entirely different than the code you originally posted.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1
Reputation: Rajendra Bansal is an unknown quantity at this point 
Solved Threads: 0
Rajendra Bansal Rajendra Bansal is offline Offline
Newbie Poster

Re: Basic Concept

 
0
  #5
Oct 10th, 2005
># 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??
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,494
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Basic Concept

 
0
  #6
Oct 10th, 2005
parentheses are required as shown in previous posts.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 2
Reputation: akshatvig19 is an unknown quantity at this point 
Solved Threads: 0
akshatvig19 akshatvig19 is offline Offline
Newbie Poster

Re: Basic Concept

 
0
  #7
Oct 13th, 2005
The same..
Paranthesis will do the work for getting p=(1,2)
so o/p will be 2.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC