Good day to all, i'm just starting to learn c language...and i have a something to know ... is the opening curly bracket and closing curly bracket mean that it will end and begin a segment in c? thank you...

Recommended Answers

All 2 Replies

That is right. And you can have as many of those as you want.

int main()
{    // start of segment

    if( something )
    {   // start of segment

    } // end of segment

} // end of segment

Just an added information :

It is called as scope definition.It is C's way of assuring something similar and far less effective "Encapsulation" technique provided by C++.
It is a way by which we set a boundary to the usage of a specific variables.It is a way in which we define where is a particular variable valid.Example:

//scope 1
{
     //scope 2
    {
          //scope 3
          {
                 //goes on
          }
    }
}

Some basics:
1>Variables declared in scope n are valid and can be used in scope m where n<m.
2>Variables declared in scope n have no meaning in scope m when n>m.
3>In case a variable with same name x is defined in scope n and scope m where n<m and operation on variable is carried out in scope m then the local value of x that is variable x of scope m is used.(General Rule : More local value will be used in the case of conflicts as above).
4>The above concept is just used to set boundaries for the variables.As shown above if a variable is declared in scope n then we limit its usage to scope m where m>=n but not in m<n.

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.