Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 139305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:24:40+00:00 2026-05-11T07:24:40+00:00

In the C programming language, it is my understanding that variables can only be

  • 0

In the C programming language, it is my understanding that variables can only be defined at the beginning of a code block, and the variable will have the scope of the block it was declared in. With that in mind, I was wondering whether it is considered bad practice to artificially create a new scope as in this example:

void foo() {      ... Do some stuff ...       if(TRUE)      {          char a;          int b;           ... Do some more stuff ...      }       ... Do even more stuff ...  } 

Assuming TRUE is set to 1 in a macro definition, would this code be considered ‘good code’ or does it make seasoned programmers cringe at the very thought of it?

Thanks for your input!

EDIT: In response to some of the answers, the code I am working with needs to work with some pretty ancient legacy systems. While it would be nice to operate on an assumption of C99, we really can’t guarantee that they will have it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:24:40+00:00Added an answer on May 11, 2026 at 7:24 am

    You don’t even need an if statement. You can create blocks with {}

    That should probably be a separate function however.

    Example here:

    #include <stdio.h>  int main(int argc, char **argv) {     int i = 0;     {         int i = 10;         printf('%d\n', i);     }     printf('%d\n', i); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the C programming language and Pthreads as the threading library; do variables/structures that
It's my understanding that C#, though created by Microsoft, is a programming language that
My understanding is that wxWidgets is for a number of programming languages (C++, Python,
Which programming language(s) were used to code Windows Vista?
Is there a programming language suitable for building web applications, that is compiled, strongly-typed,
Can anyone suggest me a helpful programming language which can be used to create
I'm reading The C++ Programming Language and in it Stroustrup states that the int
I have just started reading through The C Programming Language and I am having
Where X is any programming language (C#, Javascript, Lisp, Perl, Ruby, Scheme, etc) which
C++ was the first programming language I really got into, but the majority of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.