Take FREE!! Online Mettl Mock Test to Crack TechM and Other Companies Written Exams.
Get Off-Campus Placement Jobs Info !!!
Practice Tech Mahindra Essay Topics
Technical Discussion :: C
Home > Technical Interview Q&A > C > Discussion

3 / 123

What is a local block?

Answer:

A local block is any portion of a C program that is enclosed by the left brace ({) and the right brace (}). A C function contains left and right braces, and therefore anything between the two braces is contained in a local block. An if statement or a switch statement can also contain braces, so the portion of code between these two braces would be considered a local block.

Additionally, you might want to create your own local block without the aid of a C function or keyword construct. This is perfectly legal. Variables can be declared within local blocks, but they must be declared only at the beginning of a local block. Variables declared in this manner are visible only within the local block. Duplicate variable names declared within a local block take precedence over variables with the same name declared outside the local block. Here is an example of a program that uses local blocks:


#include
void main(void);
void main()
{
/* Begin local block for function main() */
int test_var = 10;
printf("Test variable before the if statement: %d\n", test_var);
if (test_var > 5)
{
/* Begin local block for "if" statement */
int test_var = 5;
printf("Test variable within the if statement: %d\n",
test_var);
{
/* Begin independent local block (not tied to
any function or keyword) */
int test_var = 0;
printf(
"Test variable within the independent local block:%d\n",
test_var);
}
/* End independent local block */
}
/* End local block for "if" statement */
printf("Test variable after the if statement: %d\n", test_var);
}
/* End local block for function main() */

This example program produces the following output:

Test variable before the if statement: 10

Test variable within the if statement: 5

Test variable within the independent local block: 0

Test variable after the if statement: 10

Notice that as each test_var was defined, it took precedence over the previously defined test_var. Also notice that when the if statement local block had ended, the program had reentered the scope of the original test_var, and its value was 10.

Asked In ::

Post Your Answer Here:


Rate This: +4 -0      +
Report    

Post Your Reply Here:

Alert me
q4i-reply-your-answer

Report Error

Please Login First Click Here

Rate This: +3 -0      +
Report    

Post Your Reply Here:

Alert me
q4i-reply-your-answer

Report Error

Please Login First Click Here

Rate This: +0 -0     
Report    

Post Your Reply Here:

Alert me
q4i-reply-your-answer

Report Error

Please Login First Click Here

Most Popular Qs.

Chaitenya Malviya2 months ago

Dear Raj,

               I am good here, hope you are also doing well. Last month the heritage walk conducted in our city, where i came to know about many incredible buildings and sites, which are not commonly known to all of us.

There i got a chance to meet U.N. secretory general, that was a great experience for me, and knowing of your our city is a great pleasure.

loving you,


|| Reply
vignesh vishwa2 months ago
hi everyone,
Ya..television has impact on children,but in same television help the children to learn good thing and humanity.
Sometimes we have to think out of the box,nowadays there are many programmes which help the children in gaining academic and creative knowledge too, instead of getting used to of watching television we have limit the children a certain time for watching television...by doing this they wont be distracted from thier studies and also they will be updated and satisfied.
|| Reply
R.MohanRaj B.E3 months ago

Dear client,



I am writing this mail to inform you  that  we are celebrating the occasion of Durka
festival from   8th October to 10
October. due to the fact of our cultural festival, Despite that will not able
to send the report during this period.



I apologize for that inconvenience unable to send a report
on time. we assure you that we will send the report on 11th October.



 



I looking forward  to
hearing your response

|| Reply
Deepak Pandey4 months ago

Dear Mr. Gill Roy,

we apologize for the delay in your service. Your payment process which was scheduled for 10th May (Friday) is delayed by 7 days due to 3 days of an unexpected power outage and recovery process. We are trying to process it as fast as possible. we are ensuring you that it will not recur any more. Kindly stay tuned with us.

Thank you,

Regards

Abhimanyu 

Project manager



|| Reply
Deepak Pandey4 months ago

Respected sir,

I am glad to inform you that our institute is going to organize the yearly happening fest 'TECHNICAL SYMPOSIUM' again this year. A lot of new students are going to participate in this fest. It's going to be a large gathering of new technical lovers. We are inviting your students to attend the fest and participate in it to provides new innovative ideas.

thank you 

yours sincerely 

SUNDER 

collage srepresentative 


|| Reply