![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Stephen Shankland,Corporate & legal - ZDNet | iBot | UNIX and Linux RSS News | 0 | 08-30-2007 04:00 PM |
| Is this a legal close-on-exec-move? | frequency8 | High Level Programming | 9 | 07-08-2007 10:30 AM |
| Not Legal Characters | lesstjm | Shell Programming and Scripting | 2 | 08-25-2005 04:23 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
hi friends,
the following code works fine,but the question is "is this a valid c". i really have no idea....... void func() { int x = 50; { int y; y = x + 400; printf("x = %d\n",x); printf("y = %d\n",y); } } |
| Forum Sponsor | ||
|
|
|
|||
|
Please use code tags for code, they show the spacing properly.
Code:
void func()
{
int x = 50;
{
int y;
y = x + 400;
printf("x = %d\n",x);
printf("y = %d\n",y);
}
}
Quote:
What might be confusing you is the strange by-themselves {'s, yes? Those are defining a code block, the same kind you use whenever you do if(something) { do_something(); }, but not attached to any statement. Naked ones like these are used to limit the scope of variables. The variables defined inside it, are only valid inside the code block. If you know the difference between global and local variables, then a codeblock is just one level deeper: Code:
/* global variable */
int a;
void func()
{
/* local variable */
int b;
/* variables a,b are visible here */
{
int c;
/* variables a,b,c visible here */
{
int d;
/* variables a,b,c,d visible here */
}
{
int e;
/* variables a,b,c,e visible here */
}
}
{
int f;
/* variables a,b,f visible here */
{
int g;
/* variables a,b,f,g visible here */
}
{
int g;
/* variables a,b,f,g visible here.
* Note that the value of the PREVIOUS g is not preserved! Treat this
* like a totally seperate variable. */
}
}
}
Last edited by Corona688; 05-17-2006 at 08:10 AM. |
|||
| Google UNIX.COM |